Open adamse opened 1 year ago
Disabling the following optimization under foldICmpAddConstant
generates the intended output:
// X+C >u C2 -> (X & ~C2) != C
// iff C & C2 == 0
// C2+1 is a power of 2
I wonder if we could tighten the conditions for this transformation to occur? Otherwise, the only other way is to defer this transformation which feels unnatural to do. @spatel-gh thoughts?
I haven't been active on LLVM for a few months, so cc'ing @nikic @goldsteinn @RKSimon for more up-to-date feedback.
Avoiding other canonicalizations is not a complete solution (the source might be in the form with an 'and' already), and deferring is not ideal because the IR can clearly be reduced.
You probably need to add a transform that can handle and-of-icmps with a neg-pow2-masked-value. That is, match the generalized version of this:
https://alive2.llvm.org/ce/z/6GK9Xz
It might be worth finding where the 'eq' version of the pattern is reduced to see if it can be updated to also handle 'ne': https://alive2.llvm.org/ce/z/do5rN2
Exhibited in Rust when doing some parsing: https://rust.godbolt.org/z/xv1WjY55o
cmp
's are combined, I use>
cmp
's are not combined, I use>=
Someone had this to say about the issue (referencing https://godbolt.org/z/YW6b4fMeP which puts it in LLVM IR terms):