[llvm] select m, sub/add(X, C), X --> sub/add (X, and(C, m)) (PR #82441)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 03:22:31 PST 2024


================
@@ -11660,6 +11660,24 @@ SDValue DAGCombiner::visitSELECT(SDNode *N) {
     }
   }
 
+  // select m, sub(X, C), X --> sub (X, and(C, m))
+  if (N1.getOpcode() == ISD::SUB && N1.getOperand(0) == N2 && N1->hasOneUse() &&
+      DAG.isConstantIntBuildVectorOrConstantInt(N1.getOperand(1)) &&
+      N0.getScalarValueSizeInBits() == N1.getScalarValueSizeInBits()) {
----------------
RKSimon wrote:

We need a DAG.ComputeNumSignBits(N0) == N0.getScalarValueSizeInBits() check as well

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


More information about the llvm-commits mailing list