[llvm] [ConstraintElim] Simplify `MinMaxIntrinsic` (PR #75306)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 28 03:20:55 PST 2023
================
@@ -1349,6 +1351,47 @@ static bool checkAndReplaceCondition(
return false;
}
+static bool checkAndReplaceMinMax(MinMaxIntrinsic *MinMax, ConstraintInfo &Info,
+ unsigned NumIn, unsigned NumOut,
+ Instruction *ContextInst,
+ Module *ReproducerModule,
+ ArrayRef<ReproducerEntry> ReproducerCondStack,
+ DominatorTree &DT,
+ SmallVectorImpl<Instruction *> &ToRemove) {
+ auto ReplaceMinMaxWithOperand = [&](MinMaxIntrinsic *MinMax, bool UseLHS) {
+ // TODO: generate reproducer for min/max.
+ MinMax->replaceUsesWithIf(MinMax->getOperand(UseLHS ? 0 : 1),
+ [&DT, NumIn, NumOut, ContextInst](Use &U) {
+ auto *UserI = getContextInstForUse(U);
+ auto *DTN = DT.getNode(UserI->getParent());
+ if (!DTN || DTN->getDFSNumIn() < NumIn ||
+ DTN->getDFSNumOut() > NumOut)
+ return false;
+ if (UserI->getParent() ==
+ ContextInst->getParent() &&
+ UserI->comesBefore(ContextInst))
+ return false;
+
+ return true;
+ });
+ NumCondsRemoved++;
+ if (MinMax->use_empty())
+ ToRemove.push_back(MinMax);
+ return true;
+ };
+
+ if (auto ImpliedCondition = checkCondition(
+ MinMax->getPredicate(), MinMax->getOperand(0), MinMax->getOperand(1),
+ MinMax, Info, NumIn, NumOut, ContextInst))
+ return ReplaceMinMaxWithOperand(MinMax, *ImpliedCondition);
+ if (auto ImpliedCondition = checkCondition(
+ ICmpInst::getNonStrictPredicate(MinMax->getPredicate()),
----------------
fhahn wrote:
It's not entirely obvious why this check here is needed (or the one above isn't sufficient).
I think it would be more explicit and probably slightly clearer if we explicitly check `(Op0 (non-strict-pred) Op1)` and `(Op1 (non-strict-pred) Op0)` instead?
https://github.com/llvm/llvm-project/pull/75306
More information about the llvm-commits
mailing list