http://llvm.org/bugs/show_bug.cgi?id=3923

           Summary: Undef store doesn't clobber earlier stores:
                    overaggressive instcombine
           Product: libraries
           Version: 2.5
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: minor
          Priority: P2
         Component: Scalar Optimizations
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected], [email protected]


In some admittedly naive stack-based code, I'm trying to store undef into
popped stack locations so that LLVM will optimize away unneeded stores.
However, the instcombine pass seems to eliminate undef stores before other
passes can use them.

Here's the original code:

$ llvm-dis <~/tmp/dead_store.bc 
; ModuleID = '<stdin>'

declare i32 @rand()

define i32 @foo(i32* %stack) {
entry:
        %0 = call i32 @rand()           ; <i32> [#uses=1]
        store i32 %0, i32* %stack
        %1 = load i32* %stack           ; <i32> [#uses=1]
        store i32 undef, i32* %stack
        ret i32 %1
}

GVN + DSE does the right thing:

$ opt -gvn -dse ~/tmp/dead_store.bc |llvm-dis
; ModuleID = '<stdin>'

declare i32 @rand()

define i32 @foo(i32* %stack) {
entry:
        %0 = call i32 @rand()           ; <i32> [#uses=1]
        store i32 undef, i32* %stack
        ret i32 %0
}

But instcombine alone just removes the "store i32 undef...", which means no
subsequent pass can optimize away the store I was trying to clobber.

$ opt -instcombine ~/tmp/dead_store.bc |llvm-dis
; ModuleID = '<stdin>'

declare i32 @rand()

define i32 @foo(i32* %stack) {
entry:
        %0 = call i32 @rand()           ; <i32> [#uses=2]
        store i32 %0, i32* %stack
        ret i32 %0
}

This causes -O3 and -std-compile-opts to fail to optimize the code too:

$ opt -O3 ~/tmp/dead_store.bc |llvm-dis
; ModuleID = '<stdin>'

declare i32 @rand()

define i32 @foo(i32* %stack) {
entry:
        %0 = tail call i32 @rand()              ; <i32> [#uses=2]
        store i32 %0, i32* %stack
        ret i32 %0
}


-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to