[LLVMbugs] [Bug 2234] New: llvm-gcc duplicates code for no reason?
bugzilla-daemon at cs.uiuc.edu
bugzilla-daemon at cs.uiuc.edu
Sat Apr 19 12:35:44 PDT 2008
http://llvm.org/bugs/show_bug.cgi?id=2234
Summary: llvm-gcc duplicates code for no reason?
Product: new-bugs
Version: unspecified
Platform: PC
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: new bugs
AssignedTo: unassignedbugs at nondot.org
ReportedBy: sabre at nondot.org
CC: llvmbugs at cs.uiuc.edu
Consider:
extern int bar ();
volatile int w;
int bar (void) {
if (bar())
return 0;
else
return w;
}
-O0 with opt -std-compile-opts compiles this to very reasonable code:
...
define i32 @bar() nounwind {
entry:
%tmp1 = tail call i32 @bar( ) nounwind ; <i32> [#uses=1]
%tmp2 = icmp eq i32 %tmp1, 0 ; <i1> [#uses=1]
br i1 %tmp2, label %bb4, label %UnifiedReturnBlock
bb4: ; preds = %entry
%tmp5 = volatile load i32* @w, align 4 ; <i32> [#uses=1]
ret i32 %tmp5
UnifiedReturnBlock: ; preds = %entry
ret i32 0
}
When using llvm-gcc -O3 however, I get this crazy code:
define i32 @bar() nounwind {
entry:
%tmp17 = tail call i32 @bar( ) nounwind ; <i32>
[#uses=1]
%tmp18 = icmp eq i32 %tmp17, 0 ; <i1> [#uses=1]
br i1 %tmp18, label %bb20, label %bb29
bb20: ; preds = %entry
%tmp21 = volatile load i32* @w, align 4 ; <i32> [#uses=1]
%phitmp103 = icmp eq i32 %tmp21, 0 ; <i1> [#uses=1]
br i1 %phitmp103, label %bb29, label %bb38
bb29: ; preds = %bb20, %entry
%tmp30 = volatile load i32* @w, align 4 ; <i32> [#uses=1]
%phitmp102 = icmp eq i32 %tmp30, 0 ; <i1> [#uses=1]
br i1 %phitmp102, label %bb38, label %bb47
bb38: ; preds = %bb29, %bb20
%tmp39 = volatile load i32* @w, align 4 ; <i32> [#uses=1]
%phitmp101 = icmp eq i32 %tmp39, 0 ; <i1> [#uses=1]
br i1 %phitmp101, label %bb47, label %bb56
bb47: ; preds = %bb38, %bb29
%tmp48 = volatile load i32* @w, align 4 ; <i32> [#uses=1]
%phitmp100 = icmp eq i32 %tmp48, 0 ; <i1> [#uses=1]
br i1 %phitmp100, label %bb56, label %bb65
bb56: ; preds = %bb47, %bb38
%tmp57 = volatile load i32* @w, align 4 ; <i32> [#uses=1]
%phitmp99 = icmp eq i32 %tmp57, 0 ; <i1> [#uses=1]
br i1 %phitmp99, label %bb65, label %bb74
bb65: ; preds = %bb56, %bb47
%tmp66 = volatile load i32* @w, align 4 ; <i32> [#uses=1]
%phitmp98 = icmp eq i32 %tmp66, 0 ; <i1> [#uses=1]
br i1 %phitmp98, label %bb74, label %bb83
bb74: ; preds = %bb65, %bb56
%tmp75 = volatile load i32* @w, align 4 ; <i32> [#uses=1]
%phitmp97 = icmp eq i32 %tmp75, 0 ; <i1> [#uses=1]
br i1 %phitmp97, label %bb83, label %bb92
bb83: ; preds = %bb74, %bb65
%tmp84 = volatile load i32* @w, align 4 ; <i32> [#uses=1]
%phitmp = icmp eq i32 %tmp84, 0 ; <i1> [#uses=1]
br i1 %phitmp, label %bb92, label %UnifiedReturnBlock
bb92: ; preds = %bb83, %bb74
%tmp93 = volatile load i32* @w, align 4 ; <i32> [#uses=1]
ret i32 %tmp93
UnifiedReturnBlock: ; preds = %bb83
ret i32 0
}
This is a miscompilation, because it causes multiple accesses to the volatile
value, and seems pretty pointless in general.
--
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.
More information about the llvm-bugs
mailing list