[llvm-bugs] [Bug 46940] New: Wrong code generated from instcombine
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Jul 31 12:25:13 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=46940
Bug ID: 46940
Summary: Wrong code generated from instcombine
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: kazu at google.com
CC: llvm-bugs at lists.llvm.org
I'm seeing what appears to be miscompilation after:
https://github.com/llvm/llvm-project/commit/00472067c34ccbceb2fad4b905524f3c780bb7d5
Consider:
target triple = "x86_64-grtev4-linux-gnu"
define i1 @foo(i32 %arg) {
entry:
%cmp1 = icmp eq i32 %arg, 37
br i1 %cmp1, label %bb_then, label %bb_else
bb_then:
call void @bar()
br label %bb_exit
bb_else:
%cmp2 = icmp slt i32 %arg, 17
br label %bb_exit
bb_exit:
%phi1 = phi i1 [ true, %bb_else ], [ false, %bb_then ]
%phi2 = phi i1 [ %cmp2, %bb_else ], [ undef, %bb_then ]
%and1 = and i1 %phi2, %phi1
ret i1 %and1
}
declare void @bar()
Note that for every control flow, the return value is well defined.
arg == 37 -> return false
arg < 17 -> return true
otherwise -> return false
Then
$ ./build/bin/opt -instcombine -S ~/undef2.ll -o ~/undef2-opt.ll
modifies bb_exit like so:
bb_exit: ; preds = %bb_else, %bb_then
%phi2 = phi i1 [ %cmp2, %bb_else ], [ undef, %bb_then ]
ret i1 %phi2
Notice undef in the phi node.
FWIW, immediately after SimplifyUsingControlFlow and replaceInstUsesWith
run on phi1, we have:
bb_exit: ; preds = %bb_else, %bb_then
%phi1 = phi i1 [ true, %bb_else ], [ false, %bb_then ]
%phi2 = phi i1 [ %cmp2, %bb_else ], [ undef, %bb_then ]
%0 = xor i1 %cmp1, true
%and1 = and i1 %phi2, %0
ret i1 %and1
--
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/20200731/28ba1d04/attachment.html>
More information about the llvm-bugs
mailing list