Skip to content

Commit d87b193

Browse files
committed
Move checks to FoldOpIntoSelect
1 parent 1b3e662 commit d87b193

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,29 +1654,6 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
16541654
if (Value *FreedOp = getFreedOperand(&CI, &TLI))
16551655
return visitFree(CI, FreedOp);
16561656

1657-
if (Function *F = CI.getCalledFunction()) {
1658-
if (F->getIntrinsicID() == Intrinsic::umin ||
1659-
F->getIntrinsicID() == Intrinsic::umax) {
1660-
for (Value *Arg : CI.args()) {
1661-
auto *SI = dyn_cast<SelectInst>(Arg);
1662-
if (!SI)
1663-
continue;
1664-
1665-
auto *TrueC = dyn_cast<Constant>(SI->getTrueValue());
1666-
auto *FalseC = dyn_cast<Constant>(SI->getFalseValue());
1667-
1668-
// Block only if the select is masking, e.g. select(cond, val, -1)
1669-
if ((TrueC && TrueC->isAllOnesValue()) ||
1670-
(FalseC && FalseC->isAllOnesValue())) {
1671-
LLVM_DEBUG(
1672-
dbgs()
1673-
<< "InstCombine: skipping umin/umax folding for masked select\n");
1674-
return nullptr;
1675-
}
1676-
}
1677-
}
1678-
}
1679-
16801657
// If the caller function (i.e. us, the function that contains this CallInst)
16811658
// is nounwind, mark the call as nounwind, even if the callee isn't.
16821659
if (CI.getFunction()->doesNotThrow() && !CI.doesNotThrow()) {

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,25 @@ Instruction *InstCombinerImpl::FoldOpIntoSelect(Instruction &Op, SelectInst *SI,
17191719
if (SI->getType()->isIntOrIntVectorTy(1))
17201720
return nullptr;
17211721

1722+
if (auto *II = dyn_cast<IntrinsicInst>(&Op)) {
1723+
switch (II->getIntrinsicID()) {
1724+
case Intrinsic::umin:
1725+
case Intrinsic::smin:
1726+
if (ConstantInt *C = dyn_cast<ConstantInt>(FV))
1727+
if (C->isAllOnesValue())
1728+
return nullptr;
1729+
break;
1730+
case Intrinsic::umax:
1731+
case Intrinsic::smax:
1732+
if (ConstantInt *C = dyn_cast<ConstantInt>(FV))
1733+
if (C->isZero())
1734+
return nullptr;
1735+
break;
1736+
default:
1737+
break;
1738+
}
1739+
}
1740+
17221741
// Test if a FCmpInst instruction is used exclusively by a select as
17231742
// part of a minimum or maximum operation. If so, refrain from doing
17241743
// any other folding. This helps out other analyses which understand

0 commit comments

Comments
 (0)