[llvm] [InstCombine] Simplify select if it combinated and/or/xor (PR #73362)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 11:25:27 PDT 2024


================
@@ -1687,6 +1687,120 @@ static Value *foldSelectInstWithICmpConst(SelectInst &SI, ICmpInst *ICI,
   return nullptr;
 }
 
+static Instruction *foldSelectICmpEq(SelectInst &SI, ICmpInst *ICI,
+                                     InstCombinerImpl &IC) {
+  ICmpInst::Predicate Pred = ICI->getPredicate();
+  if (!ICmpInst::isEquality(Pred))
+    return nullptr;
+
+  Value *TrueVal = SI.getTrueValue();
+  Value *FalseVal = SI.getFalseValue();
+  Value *CmpLHS = ICI->getOperand(0);
+  Value *CmpRHS = ICI->getOperand(1);
+
+  if (Pred == ICmpInst::ICMP_NE)
+    std::swap(TrueVal, FalseVal);
+
+  // Transform (X == C) ? X : Y -> (X == C) ? C : Y
+  // specific handling for Bitwise operation.
+  // https://alive2.llvm.org/ce/z/mW3eYR
----------------
dtcxzyw wrote:

It would be better to keep alive2 links in the PR description instead of codes/tests.


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


More information about the llvm-commits mailing list