Skip to content

Commit

Permalink
Revert "[InstSimplify] Support all instructions in simplifyWithOpRepl…
Browse files Browse the repository at this point in the history
…aced()"

This reverts commit 3e3e41b.

This appears to cause a stage2 miscompile of llvm-profgen.
  • Loading branch information
nikic committed Apr 24, 2023
1 parent f8e543b commit 4d05d84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
23 changes: 17 additions & 6 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ static Value *simplifyGEPInst(Type *, Value *, ArrayRef<Value *>, bool,
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) {
Expand Down Expand Up @@ -4274,8 +4270,23 @@ static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
return Simplified != V ? Simplified : nullptr;
};

return PreventSelfSimplify(
::simplifyInstructionWithOperands(I, NewOps, Q, MaxRecurse - 1));
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.
}

// If all operands are constant after substituting Op for RepOp then we can
Expand Down
5 changes: 4 additions & 1 deletion llvm/test/Transforms/InstSimplify/select-maxmin.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2136,7 +2136,10 @@ define <4 x i8> @ult_yx_umax_select_y_shuf_mask_fval(<4 x i8> %x, <4 x i8> %y) {

define i8 @select_umin_with_icmp_zero(i8 %x, i8 %y) {
; CHECK-LABEL: @select_umin_with_icmp_zero(
; CHECK-NEXT: ret i8 0
; 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]]
;
%min = call i8 @llvm.umin.i8(i8 %x, i8 %y)
%cmp = icmp eq i8 %x, 0
Expand Down

0 comments on commit 4d05d84

Please sign in to comment.