[llvm-bugs] [Bug 34133] New: Invalid optimization in the presence of shift instructions?
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Aug 9 03:58:19 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=34133
Bug ID: 34133
Summary: Invalid optimization in the presence of shift
instructions?
Product: new-bugs
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: c.cadar at imperial.ac.uk
CC: llvm-bugs at lists.llvm.org
Consider the program below:
$ cat shift.c
int a = 0;
int foo(int x) { return (a < 2) || (a >> x) ; }
int main() {
return foo(100);
}
$ clang -O1 -emit-llvm -c shift.c
$ llvm-dis shift.bc
$ cat shift.ll
...
define i32 @foo(i32) local_unnamed_addr #0 {
%2 = load i32, i32* @a, align 4, !tbaa !1
%3 = icmp slt i32 %2, 2
%4 = ashr i32 %2, %0
%5 = icmp ne i32 %4, 0
%6 = or i1 %3, %5
%7 = zext i1 %6 to i32
ret i32 %7
}
...
define i32 @main() local_unnamed_addr #0 {
%1 = tail call i32 @foo(i32 100)
ret i32 %1
}
...
Note that in the C code, the || operator has short-circuiting
behaviour, so "a >> x" should not be evaluated since the first clause
is true. However, the optimization generates code that always
executes the corresponding ashr instruction, which has undefined
behaviour in this case, as the shift amount is 100. So is this
optimization valid?
We discovered this while working with KLEE, which generates an
overshift error when the code is compiled with -O1, but not with -O0,
so we'd like to understand whether KLEE's behaviour is correct here.
Note that UBSan does not complain here, as its instrumentation
disables the optimization.
Thank you,
Cristian
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170809/2fbc3a53/attachment.html>
More information about the llvm-bugs
mailing list