[LLVMbugs] [Bug 1741] New: BasicAA miscompilation
bugzilla-daemon at cs.uiuc.edu
bugzilla-daemon at cs.uiuc.edu
Tue Oct 23 22:50:57 PDT 2007
http://llvm.org/bugs/show_bug.cgi?id=1741
Summary: BasicAA miscompilation
Product: libraries
Version: 2.1
Platform: PC
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Global Analyses
AssignedTo: unassignedbugs at nondot.org
ReportedBy: sabre at nondot.org
CC: llvmbugs at cs.uiuc.edu
Consider this code:
struct A { int x ;};
struct B : A { };
B a;
int foo(A* b) {
a.x = 1;
b->x = 0;
return a.x;
}
int main() {
foo(&a);
}
llvm-gcc incorrectly misoptimizes foo to return 1 directly. If you reduce it
down, it is because GVN is transforming this code invalidly:
target datalayout =
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
target triple = "i686-apple-darwin8"
%struct.A = type { i32 }
%struct.B = type { %struct.A }
@a = global %struct.B zeroinitializer ; <%struct.B*> [#uses=2]
define i32 @_Z3fooP1A(%struct.A* %b) {
entry:
store i32 1, i32* getelementptr (%struct.B* @a, i32 0, i32 0, i32 0),
align 8
%tmp4 = getelementptr %struct.A* %b, i32 0, i32 0 ;
<i32*> [#uses=1]
store i32 0, i32* %tmp4, align 4
%tmp7 = load i32* getelementptr (%struct.B* @a, i32 0, i32 0, i32 0),
align 8 ; <i32> [#uses=1]
ret i32 %tmp7
}
It deletes the load and makes 'ret i32 1'.
This invalid transformation is happening because BasicAA is returning no-alias
for tmp4 and the @A gep constant expr:
$ llvm-as < t.ll | opt -count-aa -gvn -count-aa-print-all-queries | llvm-dis
No alias: [4B] i32* %tmp4, [4B] i32* getelementptr (%struct.B* @a, i32 0,
i32 0, i32 0)
...
This should be investigated,
-Chris
--
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