[llvm] [SimplifyCFG] Add support for hoisting commutative instructions (PR #104805)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 19 12:25:51 PDT 2024
================
@@ -1583,6 +1583,26 @@ static void hoistLockstepIdenticalDbgVariableRecords(
}
}
+static bool areIdenticalUpToCommutativity(const Instruction *I1,
+ const Instruction *I2) {
+ if (I1->isIdenticalToWhenDefined(I2))
+ return true;
+
+ if (auto *Cmp1 = dyn_cast<CmpInst>(I1))
+ if (auto *Cmp2 = dyn_cast<CmpInst>(I2))
+ return Cmp1->getPredicate() == Cmp2->getSwappedPredicate() &&
+ Cmp1->getOperand(0) == Cmp2->getOperand(1) &&
+ Cmp1->getOperand(1) == Cmp2->getOperand(0);
+
+ if (I1->isCommutative() && I1->isSameOperationAs(I2)) {
+ return I1->getOperand(0) == I2->getOperand(1) &&
+ I1->getOperand(1) == I2->getOperand(0) &&
+ equal(drop_begin(I1->operands(), 2), drop_begin(I2->operands(), 2));
+ }
+
+ return false;
+}
----------------
nikic wrote:
You mean where the select operands are swapped with an inverted icmp? I don't think we can easily handle this here, because we hoist instructions one by one, so the icmp needs to be hoistable independently. It's not impossible, but a lot more complex than just changing the comparison logic.
https://github.com/llvm/llvm-project/pull/104805
More information about the llvm-commits
mailing list