[ValueTracking] Missed Constant Fold due to Imprecision in Knownbits::mul
For such reduced IR pattern:
define i1 @struct5_odd_index_bit2(i32 %idx) {
%i = or i32 %idx, 1
%small = and i32 %i, 3 ; i%small is 0000 00?1
%offset = mul nuw i32 %small, 5 ; %offset is 0000 ?1?1
%bit2 = and i32 %offset, 4 ; %bit2 is 0000 0100
%r = icmp ne i32 %bit2, 0
ret i1 %r
; Expected: ret i1 true, for bit 2 is always non-zero
}
which should be reduced to a constant return but opt fails to do so: https://godbolt.org/z/evfsbTW3h.
This is primarily due to the KnownBits::mul() currently only considers consecutive known bits and ignore disjoint known segments.
While a universal refinement of the mul transformer might introduce much compilation overhead, we could start with simple cases where one of the operand is a constant.
I could patch for that. Please assign it to me.
Hi @134ARG, just checking in on this. Are you still actively looking into a fix ? If you've gotten busy and you want to hand it off, I would love to take a swing on this. Let me know.
What is the real-world motivating context for this?
Hi @134ARG, just checking in on this. Are you still actively looking into a fix ? If you've gotten busy and you want to hand it off, I would love to take a swing on this. Let me know.
@sai18022001 Hey, thanks for checking in. I haven’t had enough time to keep pushing on this, so I’d be happy to hand it off.
What is the real-world motivating context for this?
After carefully evaluating the consequences of refining mul transformer, i decide to close this - indeed we currently have no obvious evidence that this refinement is profitable, and it could introduce quite a analysis overhead.