[llvm-bugs] [Bug 31125] New: [InstCombine] pairs of icmps of phis of constants are not simplified
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Nov 22 14:47:25 PST 2016
https://llvm.org/bugs/show_bug.cgi?id=31125
Bug ID: 31125
Summary: [InstCombine] pairs of icmps of phis of constants are
not simplified
Product: libraries
Version: 3.9
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: arielb1 at mail.tau.ac.il
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Created attachment 17635
--> https://llvm.org/bugs/attachment.cgi?id=17635&action=edit
A more complicated case that simplifycfg can't optimize
This seems to be the root cause of Rust issue
https://github.com/rust-lang/rust/issues/37930, which is causing slowness in
futures-rs.
Minified reproducer:
define i8 @start(i8* %addr) {
entry-block:
br label %main-loop
main-loop:
%phi = phi i8 [ 0, %entry-block ], [ 1, %core ]
%switch_0 = icmp eq i8 %phi, 0
store volatile i8 0, i8* %addr
br i1 %switch_0, label %busy-wait-phi-0, label %exit
busy-wait-phi-0:
%load = load volatile i8, i8* %addr
%icmp = icmp eq i8 %load, 0
br i1 %icmp, label %busy-wait-phi-0, label %core
core:
%switch_1 = icmp eq i8 %phi, 1
br i1 %switch_1, label %trap, label %main-loop
trap:
ret i8 1
exit:
ret i8 0
}
In the reproducer, `trap` can never be hit: %phi is obviously always 0 when you
enter core. SCCP should notice this (SimplifyCfg notices this simple case - but
it does not handle more complicated cases), but it seems to work only on
booleans, and relies on InstCombine to simplify integers to booleans.
If all icmps of the phi compare it against the same integer (e.g. if the `eq 1`
test is replaced with an `ne 0`), everything works well: InstCombine replaces
the integer with a boolean of the form
%phi = phi i1 [ true, %entry-block ], [ false, %core ]
and SCCP can work its magic.
However, if, as above, one of the icmps is against an `eq 1` and another is
against an `eq 0`, this optimization, and therefore SCCP, can't take place.
This might better be done by extending SCCP to integers instead of in
InstCombine.
--
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/20161122/1741fa3e/attachment.html>
More information about the llvm-bugs
mailing list