Open Quuxplusone opened 3 years ago
Bugzilla Link | PR52525 |
Status | NEW |
Importance | P enhancement |
Reported by | Theodoros Theodoridis (theodort@inf.ethz.ch) |
Reported on | 2021-11-16 11:03:44 -0800 |
Last modified on | 2021-11-19 03:56:06 -0800 |
Version | trunk |
Hardware | PC Linux |
CC | florian_hahn@apple.com, htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com, theodort@inf.ethz.ch |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also | PR52260 |
I'm not sure which pass should be responsible for this (instcombine and correlated-propagation are candidates), but here's a reduction - the 2nd compare is implied (false) by the first compare:
Posting the IR reduction with some notes here. Also, I was just reminded about
the "constraint-elimination" pass, so cc'ing Florian in case this example is a
candidate for that pass.
declare void @use(i8)
define i1 @src(i32 %x) {
entry:
%tx = trunc i32 %x to i8
%ugt = icmp ugt i8 %tx, 3
br i1 %ugt, label %if, label %then
then:
call void @use(i8 %tx) ; this prevents a transform in instcombine
ret i1 false
if:
%eq = icmp eq i32 %x, 0 ; the result is always 'false' because (x&255) u> 3
ret i1 %eq
}
This is an interesting example!
As for the constraint-elimination pass, decomposition/looking-through trunc
is not yet implemented. It is doable, but we need to be careful about the exact predicate that's used.
But for the example, we only need to reason about constant ranges, so we could also handle this in "correlated-propagation" (as mentioned) or in (IP)SCCP. The latter would require PredicateInfo to also add predicates for the condition in the wider type.