const SimplifyQuery &, unsigned);
static Value *simplifySelectInst(Value *, Value *, Value *,
const SimplifyQuery &, unsigned);
+static Value *simplifyInstructionWithOperands(Instruction *I,
+ ArrayRef<Value *> NewOps,
+ const SimplifyQuery &SQ,
+ unsigned MaxRecurse);
static Value *foldSelectWithBinaryOp(Value *Cond, Value *TrueVal,
Value *FalseVal) {
if (!I || !is_contained(I->operands(), Op))
return nullptr;
+ // The arguments of a phi node might refer to a value from a previous
+ // cycle iteration.
+ if (isa<PHINode>(I))
+ return nullptr;
+
if (Op->getType()->isVectorTy()) {
// For vector types, the simplification must hold per-lane, so forbid
// potentially cross-lane operations like shufflevector.
return Simplified != V ? Simplified : nullptr;
};
- if (auto *B = dyn_cast<BinaryOperator>(I))
- return PreventSelfSimplify(simplifyBinOp(B->getOpcode(), NewOps[0],
- NewOps[1], Q, MaxRecurse - 1));
-
- if (CmpInst *C = dyn_cast<CmpInst>(I))
- return PreventSelfSimplify(simplifyCmpInst(C->getPredicate(), NewOps[0],
- NewOps[1], Q, MaxRecurse - 1));
-
- if (auto *GEP = dyn_cast<GetElementPtrInst>(I))
- return PreventSelfSimplify(simplifyGEPInst(
- GEP->getSourceElementType(), NewOps[0], ArrayRef(NewOps).slice(1),
- GEP->isInBounds(), Q, MaxRecurse - 1));
-
- if (isa<SelectInst>(I))
- return PreventSelfSimplify(simplifySelectInst(
- NewOps[0], NewOps[1], NewOps[2], Q, MaxRecurse - 1));
- // TODO: We could hand off more cases to instsimplify here.
+ return PreventSelfSimplify(
+ ::simplifyInstructionWithOperands(I, NewOps, Q, MaxRecurse - 1));
}
// If all operands are constant after substituting Op for RepOp then we can
define i8 @select_umin_with_icmp_zero(i8 %x, i8 %y) {
; CHECK-LABEL: @select_umin_with_icmp_zero(
-; CHECK-NEXT: [[MIN:%.*]] = call i8 @llvm.umin.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], 0
-; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MIN]], i8 0
-; CHECK-NEXT: ret i8 [[SEL]]
+; CHECK-NEXT: ret i8 0
;
%min = call i8 @llvm.umin.i8(i8 %x, i8 %y)
%cmp = icmp eq i8 %x, 0