[LLVMbugs] [Bug 2297] New: Over-aggressive dead store elimination in instcombine
bugzilla-daemon at cs.uiuc.edu
bugzilla-daemon at cs.uiuc.edu
Wed May 7 23:58:12 PDT 2008
http://llvm.org/bugs/show_bug.cgi?id=2297
Summary: Over-aggressive dead store elimination in instcombine
Product: new-bugs
Version: unspecified
Platform: PC
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P2
Component: new bugs
AssignedTo: unassignedbugs at nondot.org
ReportedBy: sharparrow1 at yahoo.com
CC: llvmbugs at cs.uiuc.edu
int a() {
int len;
char* x = malloc(10);
x[1] = 0;
x[0] = 1;
len = strlen(x);
x[0] = 0;
b(x);
return len;
}
A bit of a manufactured testcase, but it doesn't do anything especially
unusual.
Output from llvm-gcc -c -emit-llvm | opt -mem2reg -simplifycfg -instcombine |
llvm-dis:
; ModuleID = '<stdin>'
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:32:32"
target triple = "i386-pc-linux-gnu"
define i32 @a() nounwind {
entry:
%tmp1 = call i8* @malloc( i32 10 ) nounwind ; <i8*>
[#uses=4]
%tmp3 = getelementptr i8* %tmp1, i32 1 ; <i8*> [#uses=1]
store i8 0, i8* %tmp3, align 1
%tmp7 = call i32 @strlen( i8* %tmp1 ) nounwind readonly
; <i32> [#uses=1]
store i8 0, i8* %tmp1, align 1
%tmp11 = call i32 (...)* @b( i8* %tmp1 ) nounwind ; <i32>
[#uses=0]
ret i32 %tmp7
}
declare i8* @malloc(i32) nounwind
declare i32 @strlen(i8*) nounwind readonly
declare i32 @b(...)
This is clearly not equivalent to the original program: the output depends on
whatever random junk happens to be in x[0] after malloc returns.
Another issue, which I haven't quite figured out: running the same program
through llvm-gcc -c -emit-llvm | opt -mem2reg -instcombine | llvm-dis produces
the following:
; ModuleID = '<stdin>'
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:32:32"
target triple = "i386-pc-linux-gnu"
define i32 @a() nounwind {
entry:
%tmp1 = call i8* @malloc( i32 10 ) nounwind ; <i8*>
[#uses=4]
%tmp3 = getelementptr i8* %tmp1, i32 1 ; <i8*> [#uses=1]
store i8 0, i8* %tmp3, align 1
store i8 0, i8* %tmp1, align 1
%tmp11 = call i32 (...)* @b( i8* %tmp1 ) nounwind ; <i32>
[#uses=0]
br label %return
return: ; preds = %entry
%tmp7 = call i32 @strlen( i8* %tmp1 ) nounwind readonly
; <i32> [#uses=1]
ret i32 %tmp7
}
declare i8* @malloc(i32) nounwind
declare i32 @strlen(i8*) nounwind readonly
declare i32 @b(...)
It's clearly wrong to reorder the strlen call in that way.
--
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