[llvm] [InstCombine] Fold `(op x, ({z,s}ext (icmp eq x, C)))` to select (PR #89020)

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 17 09:54:07 PDT 2024


================
@@ -4734,6 +4734,89 @@ void InstCombinerImpl::tryToSinkInstructionDbgValues(
   }
 }
 
+// If we have:
+//  `(op X, (zext/sext (icmp eq X, C)))`
+// We can transform it to:
+//  `(select (icmp eq X, C), (op C, (zext/sext 1)), (op X, 0))`
+// We do so if the `zext/sext` is one use and `(op X, 0)` simplifies.
+Value *InstCombinerImpl::foldOpOfXWithXEqC(Value *Op, const SimplifyQuery &SQ) {
----------------
goldsteinn wrote:

> I'd like to handle `add X, (zext/sext (icmp eq/ne X, C))` first. The current version looks like an over-generalization.

I can see the argument that the intrinsics complicate the situation a bit and can drop those if you feel strongly, but imo the rest of the code is basically the same if its just add vs any op.

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


More information about the llvm-commits mailing list