[llvm] [LLVM][InstCombine] Add simplification of SVE compare intrinsics. (PR #211249)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 28 08:52:33 PDT 2026


================
@@ -1964,6 +2018,79 @@ simplifySVEIntrinsicBinOp(InstCombiner &IC, IntrinsicInst &II,
   return IC.replaceInstUsesWith(II, SimpleII);
 }
 
+static std::optional<Instruction *>
+simplifySVEIntrinsicCompare(InstCombiner &IC, IntrinsicInst &II,
+                            const SVEIntrinsicInfo &IInfo) {
+  const unsigned Opc = IInfo.getMatchingIROpode();
+  assert((Opc == Instruction::ICmp || Opc == Instruction::FCmp) &&
+         "Expected a compare operation!");
+
+  Value *Pg = II.getOperand(0);
+  Value *LHS = II.getOperand(1);
+  Value *RHS = II.getOperand(2);
+  CmpInst::Predicate CmpPred = IInfo.getCmpPredicate();
+  const DataLayout &DL = II.getDataLayout();
+
+  // Canonicalise integer constants to the RHS.
+  if (Opc == Instruction::ICmp && ICmpInst::isCommutative(CmpPred) &&
+      isa<Constant>(LHS) && !isa<Constant>(RHS) &&
+      LHS->getType() == RHS->getType()) {
+    IC.replaceOperand(II, 1, RHS);
+    IC.replaceOperand(II, 2, LHS);
+    return &II;
+  }
+
+  // Canonicalise floating-point constants to the RHS.
+  if (Opc == Instruction::FCmp && FCmpInst::isCommutative(CmpPred) &&
+      isa<Constant>(LHS) && !isa<Constant>(RHS)) {
+    assert(LHS->getType() == RHS->getType() && "Unexpected wide compare!");
+    IC.replaceOperand(II, 1, RHS);
+    IC.replaceOperand(II, 2, LHS);
+    return &II;
+  }
----------------
paulwalker-arm wrote:

I restructured the code to make wide-icmp handling more explicit.

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


More information about the llvm-commits mailing list