[llvm] [InstCombine] Remove the canonicalization of `trunc` to `i1` (PR #84628)

via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 9 09:41:04 PST 2024


YanWQ-monad wrote:

May I ask a question about fixing this regression?

https://github.com/llvm/llvm-project/pull/84628/files#diff-8029a15d86a03b733e3d58345f03e5b45ec2c335e399cf6be07ac4247a67021cL249-R254

With the original canonicalization, `trunc X to i1` would be canonicalized to `Y = and X, 1` and `icmp ne Y, 0`, which enables some optimization like the folding of `(icmp Pred1 V1, C1) | (icmp Pred2 V2, C2)`. But without the canonicalization, it failed to match `trunc` as `icmp`, which results in regression.
https://github.com/llvm/llvm-project/blob/b4001e32b1aa4df07dc6babefba19f2b77f487c6/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp#L3678-L3682

The problem is that, the parameters for that series of functions are passed using `ICmpInst`. In order to reuse the code, it might be necessary to make changes to the signature and the body of the functions, to make them accept `TruncInst`.
I don't know whether it's elegant or acceptable, or there is a better way to handle it. Thanks.

https://github.com/llvm/llvm-project/pull/84628


More information about the llvm-commits mailing list