[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:53:51 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;
+ }
+
+ // Only active lanes matter when simplifying the operation.
+ LHS = stripInactiveLanes(LHS, Pg);
+ RHS = stripInactiveLanes(RHS, Pg);
+
+ if (LHS->getType() != RHS->getType()) {
+ // We can do more for wide compares, but not using simplifyCmpInst.
----------------
paulwalker-arm wrote:
The assert exists to verify the expected inputs. However, I've implemented your suggestion and so the assert is no longer necessary.
https://github.com/llvm/llvm-project/pull/211249
More information about the llvm-commits
mailing list