Skip to content

Commit 41a9445

Browse files
committed
Prototype fix
1 parent 752adc3 commit 41a9445

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,25 @@ 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 || F->getIntrinsicID() == Intrinsic::umax) {
1659+
for (Value *Arg : CI.args()) {
1660+
auto *SI = dyn_cast<SelectInst>(Arg);
1661+
if (!SI)
1662+
continue;
1663+
1664+
auto *TrueC = dyn_cast<Constant>(SI->getTrueValue());
1665+
auto *FalseC = dyn_cast<Constant>(SI->getFalseValue());
1666+
1667+
// Block only if the select is masking, e.g. select(cond, val, -1)
1668+
if ((TrueC && TrueC->isAllOnesValue()) || (FalseC && FalseC->isAllOnesValue())) {
1669+
LLVM_DEBUG(dbgs() << "InstCombine: skipping umin/umax folding for masked select\n");
1670+
return nullptr;
1671+
}
1672+
}
1673+
}
1674+
}
1675+
16571676
// If the caller function (i.e. us, the function that contains this CallInst)
16581677
// is nounwind, mark the call as nounwind, even if the callee isn't.
16591678
if (CI.getFunction()->doesNotThrow() && !CI.doesNotThrow()) {

llvm/test/Transforms/InstCombine/select.ll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5047,3 +5047,18 @@ define <2 x ptr> @select_freeze_constant_expression_vector_gep(i1 %cond, <2 x pt
50475047
%sel = select i1 %cond, <2 x ptr> %y, <2 x ptr> %freeze
50485048
ret <2 x ptr> %sel
50495049
}
5050+
5051+
declare i8 @llvm.umin.i8(i8, i8)
5052+
5053+
define i8 @no_fold_masked_min(i8 %acc, i8 %val, i8 %mask) {
5054+
; CHECK-LABEL: @no_fold_masked_min(
5055+
; CHECK-NEXT: [[COND:%.*]] = icmp eq i8 [[MASK:%.*]], 0
5056+
; CHECK-NEXT: [[MASKED_VAL:%.*]] = select i1 [[COND:%.*]], i8 [[VAL:%.*]], i8 -1
5057+
; CHECK-NEXT: [[RES:%.*]] = call i8 @llvm.umin.i8(i8 [[ACC:%.*]], i8 [[MASKED_VAL:%.*]])
5058+
; CHECK-NEXT: ret i8 [[RES]]
5059+
;
5060+
%cond = icmp eq i8 %mask, 0
5061+
%masked_val = select i1 %cond, i8 %val, i8 -1
5062+
%res = call i8 @llvm.umin.i8(i8 %acc, i8 %masked_val)
5063+
ret i8 %res
5064+
}

0 commit comments

Comments
 (0)