Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 49 additions & 44 deletions llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could the PHI node restriction also be removed so freeze can be pushed through PHIs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The phi case is trickier because we need to make sure that we don't end up pushing a freeze around a loop. We should at least extend foldFreezeIntoRecurrence() to allow freezing multiple out-of-loop values though.

Original file line number Diff line number Diff line change
Expand Up @@ -4961,63 +4961,68 @@ Instruction *InstCombinerImpl::visitLandingPadInst(LandingPadInst &LI) {
Value *
InstCombinerImpl::pushFreezeToPreventPoisonFromPropagating(FreezeInst &OrigFI) {
// Try to push freeze through instructions that propagate but don't produce
// poison as far as possible. If an operand of freeze follows three
// conditions 1) one-use, 2) does not produce poison, and 3) has all but one
// guaranteed-non-poison operands then push the freeze through to the one
// operand that is not guaranteed non-poison. The actual transform is as
// follows.
// Op1 = ... ; Op1 can be posion
// Op0 = Inst(Op1, NonPoisonOps...) ; Op0 has only one use and only have
// ; single guaranteed-non-poison operands
// poison as far as possible. If an operand of freeze does not produce poison
// then push the freeze through to the operands that are not guaranteed
// non-poison. The actual transform is as follows.
// Op1 = ... ; Op1 can be poison
// Op0 = Inst(Op1, NonPoisonOps...)
// ... = Freeze(Op0)
// =>
// Op1 = ...
// Op1.fr = Freeze(Op1)
// ... = Inst(Op1.fr, NonPoisonOps...)
auto *OrigOp = OrigFI.getOperand(0);
auto *OrigOpInst = dyn_cast<Instruction>(OrigOp);

// While we could change the other users of OrigOp to use freeze(OrigOp), that
// potentially reduces their optimization potential, so let's only do this iff
// the OrigOp is only used by the freeze.
if (!OrigOpInst || !OrigOpInst->hasOneUse() || isa<PHINode>(OrigOp))
return nullptr;
auto CanPushFreeze = [](Value *V) {
if (!isa<Instruction>(V) || isa<PHINode>(V))
return false;

// We can't push the freeze through an instruction which can itself create
// poison. If the only source of new poison is flags, we can simply
// strip them (since we know the only use is the freeze and nothing can
// benefit from them.)
if (canCreateUndefOrPoison(cast<Operator>(OrigOp),
/*ConsiderFlagsAndMetadata*/ false))
return nullptr;
// We can't push the freeze through an instruction which can itself create
// poison. If the only source of new poison is flags, we can simply
// strip them (since we know the only use is the freeze and nothing can
// benefit from them.)
return !canCreateUndefOrPoison(cast<Operator>(V),
/*ConsiderFlagsAndMetadata*/ false);
};

// If operand is guaranteed not to be poison, there is no need to add freeze
// to the operand. So we first find the operand that is not guaranteed to be
// poison.
Value *MaybePoisonOperand = nullptr;
for (Value *V : OrigOpInst->operands()) {
if (isa<MetadataAsValue>(V) || isGuaranteedNotToBeUndefOrPoison(V) ||
// Treat identical operands as a single operand.
(MaybePoisonOperand && MaybePoisonOperand == V))
// Pushing freezes up long instruction chains can be expensive. Instead,
// we directly push the freeze all the way to the leaves. However, we leave
// deduplication of freezes on the same value for freezeOtherUses().
Use *OrigUse = &OrigFI.getOperandUse(0);
SmallPtrSet<Instruction *, 8> Visited;
SmallVector<Use *, 8> Worklist;
Worklist.push_back(OrigUse);
while (!Worklist.empty()) {
auto *U = Worklist.pop_back_val();
Value *V = U->get();
if (!CanPushFreeze(V)) {
// If we can't push through the original instruction, abort the transform.
if (U == OrigUse)
return nullptr;

auto *UserI = cast<Instruction>(U->getUser());
Builder.SetInsertPoint(UserI);
Value *Frozen = Builder.CreateFreeze(V, V->getName() + ".fr");
U->set(Frozen);
continue;
if (!MaybePoisonOperand)
MaybePoisonOperand = V;
else
return nullptr;
}
}

OrigOpInst->dropPoisonGeneratingAnnotations();
auto *I = cast<Instruction>(V);
if (!Visited.insert(I).second)
continue;

// If all operands are guaranteed to be non-poison, we can drop freeze.
if (!MaybePoisonOperand)
return OrigOp;
// reverse() to emit freezes in a more natural order.
for (Use &Op : reverse(I->operands())) {
Value *OpV = Op.get();
if (isa<MetadataAsValue>(OpV) || isGuaranteedNotToBeUndefOrPoison(OpV))
continue;
Worklist.push_back(&Op);
}

Builder.SetInsertPoint(OrigOpInst);
Value *FrozenMaybePoisonOperand = Builder.CreateFreeze(
MaybePoisonOperand, MaybePoisonOperand->getName() + ".fr");
I->dropPoisonGeneratingAnnotations();
this->Worklist.add(I);
}

OrigOpInst->replaceUsesOfWith(MaybePoisonOperand, FrozenMaybePoisonOperand);
return OrigOp;
return OrigUse->get();
}

Instruction *InstCombinerImpl::foldFreezeIntoRecurrence(FreezeInst &FI,
Expand Down
5 changes: 3 additions & 2 deletions llvm/test/Transforms/InstCombine/freeze-fp-ops.ll
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ define float @freeze_sqrt(float %arg) {
define float @freeze_powi(float %arg0, i32 %arg1) {
; CHECK-LABEL: define float @freeze_powi(
; CHECK-SAME: float [[ARG0:%.*]], i32 [[ARG1:%.*]]) {
; CHECK-NEXT: [[OP:%.*]] = call float @llvm.powi.f32.i32(float [[ARG0]], i32 [[ARG1]])
; CHECK-NEXT: [[FREEZE:%.*]] = freeze float [[OP]]
; CHECK-NEXT: [[ARG0_FR:%.*]] = freeze float [[ARG0]]
; CHECK-NEXT: [[ARG1_FR:%.*]] = freeze i32 [[ARG1]]
; CHECK-NEXT: [[FREEZE:%.*]] = call float @llvm.powi.f32.i32(float [[ARG0_FR]], i32 [[ARG1_FR]])
; CHECK-NEXT: ret float [[FREEZE]]
;
%op = call float @llvm.powi.f32.i32(float %arg0, i32 %arg1)
Expand Down
95 changes: 46 additions & 49 deletions llvm/test/Transforms/InstCombine/freeze.ll
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ define <3 x i4> @partial_undef_vec() {
; Move the freeze forward to prevent poison from spreading.

define i32 @early_freeze_test1(i32 %x, i32 %y) {
; CHECK-LABEL: define i32 @early_freeze_test1(
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
; CHECK-NEXT: [[V1:%.*]] = add i32 [[X]], [[Y]]
; CHECK-NEXT: [[V1_FR:%.*]] = freeze i32 [[V1]]
; CHECK-NEXT: [[V2:%.*]] = shl i32 [[V1_FR]], 1
; CHECK-LABEL: @early_freeze_test1(
; CHECK-NEXT: [[X_FR:%.*]] = freeze i32 [[X:%.*]]
; CHECK-NEXT: [[Y_FR:%.*]] = freeze i32 [[Y:%.*]]
; CHECK-NEXT: [[V1:%.*]] = add i32 [[X_FR]], [[Y_FR]]
; CHECK-NEXT: [[V2:%.*]] = shl i32 [[V1]], 1
; CHECK-NEXT: [[V3:%.*]] = and i32 [[V2]], 2
; CHECK-NEXT: ret i32 [[V3]]
;
Expand Down Expand Up @@ -153,9 +153,8 @@ define i32 @early_freeze_test3(i32 %v1) {
}

define i32 @early_freeze_test4(i32 %v1) {
; CHECK-LABEL: define i32 @early_freeze_test4(
; CHECK-SAME: i32 [[V1:%.*]]) {
; CHECK-NEXT: [[V1_FR:%.*]] = freeze i32 [[V1]]
; CHECK-LABEL: @early_freeze_test4(
; CHECK-NEXT: [[V1_FR:%.*]] = freeze i32 [[V1:%.*]]
; CHECK-NEXT: [[V2:%.*]] = mul i32 [[V1_FR]], [[V1_FR]]
; CHECK-NEXT: ret i32 [[V2]]
;
Expand Down Expand Up @@ -938,21 +937,20 @@ exit: ; preds = %loop
}

; The recurrence for the GEP offset can't produce poison so the freeze should
; be pushed through to the ptr, but this is not currently supported.
; be pushed through to the ptr.
define void @fold_phi_gep_phi_offset(ptr %init, ptr %end, i64 noundef %n) {
; CHECK-LABEL: define void @fold_phi_gep_phi_offset(
; CHECK-SAME: ptr [[INIT:%.*]], ptr [[END:%.*]], i64 noundef [[N:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*]]:
; CHECK-NEXT: br label %[[LOOP:.*]]
; CHECK: [[LOOP]]:
; CHECK-NEXT: [[I:%.*]] = phi ptr [ [[INIT]], %[[ENTRY]] ], [ [[I_NEXT_FR:%.*]], %[[LOOP]] ]
; CHECK-NEXT: [[OFF:%.*]] = phi i64 [ [[N]], %[[ENTRY]] ], [ [[OFF_NEXT:%.*]], %[[LOOP]] ]
; CHECK-LABEL: @fold_phi_gep_phi_offset(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = freeze ptr [[INIT:%.*]]
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: [[I:%.*]] = phi ptr [ [[TMP0]], [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
; CHECK-NEXT: [[OFF:%.*]] = phi i64 [ [[N:%.*]], [[ENTRY]] ], [ [[OFF_NEXT:%.*]], [[LOOP]] ]
; CHECK-NEXT: [[OFF_NEXT]] = shl i64 [[OFF]], 3
; CHECK-NEXT: [[I_NEXT:%.*]] = getelementptr i8, ptr [[I]], i64 [[OFF_NEXT]]
; CHECK-NEXT: [[I_NEXT_FR]] = freeze ptr [[I_NEXT]]
; CHECK-NEXT: [[COND:%.*]] = icmp eq ptr [[I_NEXT_FR]], [[END]]
; CHECK-NEXT: br i1 [[COND]], label %[[LOOP]], label %[[EXIT:.*]]
; CHECK: [[EXIT]]:
; CHECK-NEXT: [[I_NEXT]] = getelementptr i8, ptr [[I]], i64 [[OFF_NEXT]]
; CHECK-NEXT: [[COND:%.*]] = icmp eq ptr [[I_NEXT]], [[END:%.*]]
; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT:%.*]]
; CHECK: exit:
; CHECK-NEXT: ret void
;
entry:
Expand All @@ -971,22 +969,21 @@ exit: ; preds = %loop
ret void
}

; Offset is still guaranteed not to be poison, so the freeze could be moved
; here if we strip inbounds from the GEP, but this is not currently supported.
; Offset is still guaranteed not to be poison, so the freeze can be moved
; here if we strip inbounds from the GEP.
define void @fold_phi_gep_inbounds_phi_offset(ptr %init, ptr %end, i64 noundef %n) {
; CHECK-LABEL: define void @fold_phi_gep_inbounds_phi_offset(
; CHECK-SAME: ptr [[INIT:%.*]], ptr [[END:%.*]], i64 noundef [[N:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*]]:
; CHECK-NEXT: br label %[[LOOP:.*]]
; CHECK: [[LOOP]]:
; CHECK-NEXT: [[I:%.*]] = phi ptr [ [[INIT]], %[[ENTRY]] ], [ [[I_NEXT_FR:%.*]], %[[LOOP]] ]
; CHECK-NEXT: [[OFF:%.*]] = phi i64 [ [[N]], %[[ENTRY]] ], [ [[OFF_NEXT:%.*]], %[[LOOP]] ]
; CHECK-LABEL: @fold_phi_gep_inbounds_phi_offset(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = freeze ptr [[INIT:%.*]]
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: [[I:%.*]] = phi ptr [ [[TMP0]], [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
; CHECK-NEXT: [[OFF:%.*]] = phi i64 [ [[N:%.*]], [[ENTRY]] ], [ [[OFF_NEXT:%.*]], [[LOOP]] ]
; CHECK-NEXT: [[OFF_NEXT]] = shl i64 [[OFF]], 3
; CHECK-NEXT: [[I_NEXT:%.*]] = getelementptr inbounds i8, ptr [[I]], i64 [[OFF_NEXT]]
; CHECK-NEXT: [[I_NEXT_FR]] = freeze ptr [[I_NEXT]]
; CHECK-NEXT: [[COND:%.*]] = icmp eq ptr [[I_NEXT_FR]], [[END]]
; CHECK-NEXT: br i1 [[COND]], label %[[LOOP]], label %[[EXIT:.*]]
; CHECK: [[EXIT]]:
; CHECK-NEXT: [[I_NEXT]] = getelementptr i8, ptr [[I]], i64 [[OFF_NEXT]]
; CHECK-NEXT: [[COND:%.*]] = icmp eq ptr [[I_NEXT]], [[END:%.*]]
; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT:%.*]]
; CHECK: exit:
; CHECK-NEXT: ret void
;
entry:
Expand All @@ -1005,21 +1002,21 @@ exit: ; preds = %loop
ret void
}

; GEP can produce poison, check freeze isn't moved.
define void @cant_fold_phi_gep_phi_offset(ptr %init, ptr %end, i64 %n) {
; CHECK-LABEL: define void @cant_fold_phi_gep_phi_offset(
; CHECK-SAME: ptr [[INIT:%.*]], ptr [[END:%.*]], i64 [[N:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*]]:
; CHECK-NEXT: br label %[[LOOP:.*]]
; CHECK: [[LOOP]]:
; CHECK-NEXT: [[I:%.*]] = phi ptr [ [[INIT]], %[[ENTRY]] ], [ [[I_NEXT_FR:%.*]], %[[LOOP]] ]
; CHECK-NEXT: [[OFF:%.*]] = phi i64 [ [[N]], %[[ENTRY]] ], [ [[OFF_NEXT:%.*]], %[[LOOP]] ]
; Same as previous, but also requires freezing %n.
define void @fold_phi_gep_phi_offset_multiple(ptr %init, ptr %end, i64 %n) {
; CHECK-LABEL: @fold_phi_gep_phi_offset_multiple(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = freeze ptr [[INIT:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = freeze i64 [[N:%.*]]
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: [[I:%.*]] = phi ptr [ [[TMP0]], [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
; CHECK-NEXT: [[OFF:%.*]] = phi i64 [ [[TMP1]], [[ENTRY]] ], [ [[OFF_NEXT:%.*]], [[LOOP]] ]
; CHECK-NEXT: [[OFF_NEXT]] = shl i64 [[OFF]], 3
; CHECK-NEXT: [[I_NEXT:%.*]] = getelementptr inbounds i8, ptr [[I]], i64 [[OFF_NEXT]]
; CHECK-NEXT: [[I_NEXT_FR]] = freeze ptr [[I_NEXT]]
; CHECK-NEXT: [[COND:%.*]] = icmp eq ptr [[I_NEXT_FR]], [[END]]
; CHECK-NEXT: br i1 [[COND]], label %[[LOOP]], label %[[EXIT:.*]]
; CHECK: [[EXIT]]:
; CHECK-NEXT: [[I_NEXT]] = getelementptr i8, ptr [[I]], i64 [[OFF_NEXT]]
; CHECK-NEXT: [[COND:%.*]] = icmp eq ptr [[I_NEXT]], [[END:%.*]]
; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT:%.*]]
; CHECK: exit:
; CHECK-NEXT: ret void
;
entry:
Expand Down
7 changes: 3 additions & 4 deletions llvm/test/Transforms/InstCombine/icmp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5838,10 +5838,9 @@ entry:
define i1 @icmp_freeze_sext(i16 %x, i16 %y) {
; CHECK-LABEL: define i1 @icmp_freeze_sext(
; CHECK-SAME: i16 [[X:%.*]], i16 [[Y:%.*]]) {
; CHECK-NEXT: [[CMP1:%.*]] = icmp uge i16 [[X]], [[Y]]
; CHECK-NEXT: [[CMP1_FR:%.*]] = freeze i1 [[CMP1]]
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i16 [[Y]], 0
; CHECK-NEXT: [[CMP2:%.*]] = or i1 [[TMP1]], [[CMP1_FR]]
; CHECK-NEXT: [[Y_FR:%.*]] = freeze i16 [[Y]]
; CHECK-NEXT: [[X_FR:%.*]] = freeze i16 [[X]]
; CHECK-NEXT: [[CMP2:%.*]] = icmp uge i16 [[X_FR]], [[Y_FR]]
; CHECK-NEXT: ret i1 [[CMP2]]
;
%cmp1 = icmp uge i16 %x, %y
Expand Down
7 changes: 4 additions & 3 deletions llvm/test/Transforms/InstCombine/nsw.ll
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,10 @@ define i32 @sub_sub1_nsw_nsw(i32 %a, i32 %b, i32 %c) {

define i8 @neg_nsw_freeze(i8 %a1, i8 %a2) {
; CHECK-LABEL: @neg_nsw_freeze(
; CHECK-NEXT: [[A_NEG:%.*]] = sub nsw i8 [[A2:%.*]], [[A1:%.*]]
; CHECK-NEXT: [[FR_NEG:%.*]] = freeze i8 [[A_NEG]]
; CHECK-NEXT: ret i8 [[FR_NEG]]
; CHECK-NEXT: [[A1_FR:%.*]] = freeze i8 [[A1:%.*]]
; CHECK-NEXT: [[A2_FR:%.*]] = freeze i8 [[A2:%.*]]
; CHECK-NEXT: [[A_NEG:%.*]] = sub i8 [[A2_FR]], [[A1_FR]]
; CHECK-NEXT: ret i8 [[A_NEG]]
;
%a = sub nsw i8 %a1, %a2
%fr = freeze i8 %a
Expand Down
18 changes: 10 additions & 8 deletions llvm/test/Transforms/InstCombine/select.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2847,7 +2847,8 @@ define void @cond_freeze_multipleuses(i8 %x, i8 %y) {
define i32 @select_freeze_icmp_eq(i32 %x, i32 %y) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comes from:

static Value *foldSelectWithFrozenICmp(SelectInst &Sel, InstCombiner::BuilderTy &Builder) {

We regress this case by inserting an unnecessary freeze now, but I don't think this is important. We can drop the specialized transform after this patch.

; CHECK-LABEL: define i32 @select_freeze_icmp_eq(
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
; CHECK-NEXT: ret i32 [[Y]]
; CHECK-NEXT: [[Y_FR:%.*]] = freeze i32 [[Y]]
; CHECK-NEXT: ret i32 [[Y_FR]]
;
%c = icmp eq i32 %x, %y
%c.fr = freeze i1 %c
Expand All @@ -2858,7 +2859,8 @@ define i32 @select_freeze_icmp_eq(i32 %x, i32 %y) {
define i32 @select_freeze_icmp_ne(i32 %x, i32 %y) {
; CHECK-LABEL: define i32 @select_freeze_icmp_ne(
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
; CHECK-NEXT: ret i32 [[X]]
; CHECK-NEXT: [[X_FR:%.*]] = freeze i32 [[X]]
; CHECK-NEXT: ret i32 [[X_FR]]
;
%c = icmp ne i32 %x, %y
%c.fr = freeze i1 %c
Expand All @@ -2869,9 +2871,9 @@ define i32 @select_freeze_icmp_ne(i32 %x, i32 %y) {
define i32 @select_freeze_icmp_else(i32 %x, i32 %y) {
; CHECK-LABEL: define i32 @select_freeze_icmp_else(
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[X]], [[Y]]
; CHECK-NEXT: [[C_FR:%.*]] = freeze i1 [[C]]
; CHECK-NEXT: [[V:%.*]] = select i1 [[C_FR]], i32 [[X]], i32 [[Y]]
; CHECK-NEXT: [[Y_FR:%.*]] = freeze i32 [[Y]]
; CHECK-NEXT: [[X_FR:%.*]] = freeze i32 [[X]]
; CHECK-NEXT: [[V:%.*]] = call i32 @llvm.umin.i32(i32 [[X_FR]], i32 [[Y_FR]])
; CHECK-NEXT: ret i32 [[V]]
;
%c = icmp ult i32 %x, %y
Expand All @@ -2885,9 +2887,9 @@ declare void @use_i1_i32(i1, i32)
define void @select_freeze_icmp_multuses(i32 %x, i32 %y) {
; CHECK-LABEL: define void @select_freeze_icmp_multuses(
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[X]], [[Y]]
; CHECK-NEXT: [[C_FR:%.*]] = freeze i1 [[C]]
; CHECK-NEXT: [[V:%.*]] = select i1 [[C_FR]], i32 [[X]], i32 [[Y]]
; CHECK-NEXT: [[Y_FR:%.*]] = freeze i32 [[Y]]
; CHECK-NEXT: [[V:%.*]] = freeze i32 [[X]]
; CHECK-NEXT: [[C_FR:%.*]] = icmp ne i32 [[V]], [[Y_FR]]
; CHECK-NEXT: call void @use_i1_i32(i1 [[C_FR]], i32 [[V]])
; CHECK-NEXT: ret void
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1446,8 +1446,9 @@ define i8 @dont_negate_ordinary_select(i8 %x, i8 %y, i8 %z, i1 %c) {
define i4 @negate_freeze(i4 %x, i4 %y, i4 %z) {
; CHECK-LABEL: define i4 @negate_freeze(
; CHECK-SAME: i4 [[X:%.*]], i4 [[Y:%.*]], i4 [[Z:%.*]]) {
; CHECK-NEXT: [[T0_NEG:%.*]] = sub i4 [[Y]], [[X]]
; CHECK-NEXT: [[T1_NEG:%.*]] = freeze i4 [[T0_NEG]]
; CHECK-NEXT: [[X_FR:%.*]] = freeze i4 [[X]]
; CHECK-NEXT: [[Y_FR:%.*]] = freeze i4 [[Y]]
; CHECK-NEXT: [[T1_NEG:%.*]] = sub i4 [[Y_FR]], [[X_FR]]
; CHECK-NEXT: [[T2:%.*]] = add i4 [[T1_NEG]], [[Z]]
; CHECK-NEXT: ret i4 [[T2]]
;
Expand All @@ -1459,8 +1460,9 @@ define i4 @negate_freeze(i4 %x, i4 %y, i4 %z) {
define i4 @negate_freeze_extrause(i4 %x, i4 %y, i4 %z) {
; CHECK-LABEL: define i4 @negate_freeze_extrause(
; CHECK-SAME: i4 [[X:%.*]], i4 [[Y:%.*]], i4 [[Z:%.*]]) {
; CHECK-NEXT: [[T0:%.*]] = sub i4 [[X]], [[Y]]
; CHECK-NEXT: [[T1:%.*]] = freeze i4 [[T0]]
; CHECK-NEXT: [[X_FR:%.*]] = freeze i4 [[X]]
; CHECK-NEXT: [[Y_FR:%.*]] = freeze i4 [[Y]]
; CHECK-NEXT: [[T1:%.*]] = sub i4 [[X_FR]], [[Y_FR]]
; CHECK-NEXT: call void @use4(i4 [[T1]])
; CHECK-NEXT: [[T2:%.*]] = sub i4 [[Z]], [[T1]]
; CHECK-NEXT: ret i4 [[T2]]
Expand Down
10 changes: 6 additions & 4 deletions llvm/test/Transforms/InstCombine/sub-of-negatible.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1543,8 +1543,9 @@ define <2 x i32> @negate_select_of_negation_poison(<2 x i1> %c, <2 x i32> %x) {
define i4 @negate_freeze(i4 %x, i4 %y, i4 %z) {
; CHECK-LABEL: define i4 @negate_freeze(
; CHECK-SAME: i4 [[X:%.*]], i4 [[Y:%.*]], i4 [[Z:%.*]]) {
; CHECK-NEXT: [[T0_NEG:%.*]] = sub i4 [[Y]], [[X]]
; CHECK-NEXT: [[T1_NEG:%.*]] = freeze i4 [[T0_NEG]]
; CHECK-NEXT: [[X_FR:%.*]] = freeze i4 [[X]]
; CHECK-NEXT: [[Y_FR:%.*]] = freeze i4 [[Y]]
; CHECK-NEXT: [[T1_NEG:%.*]] = sub i4 [[Y_FR]], [[X_FR]]
; CHECK-NEXT: [[T2:%.*]] = add i4 [[T1_NEG]], [[Z]]
; CHECK-NEXT: ret i4 [[T2]]
;
Expand All @@ -1556,8 +1557,9 @@ define i4 @negate_freeze(i4 %x, i4 %y, i4 %z) {
define i4 @negate_freeze_extrause(i4 %x, i4 %y, i4 %z) {
; CHECK-LABEL: define i4 @negate_freeze_extrause(
; CHECK-SAME: i4 [[X:%.*]], i4 [[Y:%.*]], i4 [[Z:%.*]]) {
; CHECK-NEXT: [[T0:%.*]] = sub i4 [[X]], [[Y]]
; CHECK-NEXT: [[T1:%.*]] = freeze i4 [[T0]]
; CHECK-NEXT: [[X_FR:%.*]] = freeze i4 [[X]]
; CHECK-NEXT: [[Y_FR:%.*]] = freeze i4 [[Y]]
; CHECK-NEXT: [[T1:%.*]] = sub i4 [[X_FR]], [[Y_FR]]
; CHECK-NEXT: call void @use4(i4 [[T1]])
; CHECK-NEXT: [[T2:%.*]] = sub i4 [[Z]], [[T1]]
; CHECK-NEXT: ret i4 [[T2]]
Expand Down
7 changes: 4 additions & 3 deletions llvm/test/Transforms/InstCombine/urem-via-cmp-select.ll
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ define i8 @urem_assume_with_unexpected_const(i8 %x, i8 %n) {
define i8 @urem_without_assume(i8 %arg, i8 %arg2) {
; CHECK-LABEL: define i8 @urem_without_assume(
; CHECK-SAME: i8 [[ARG:%.*]], i8 [[ARG2:%.*]]) {
; CHECK-NEXT: [[X:%.*]] = urem i8 [[ARG]], [[ARG2]]
; CHECK-NEXT: [[X_FR:%.*]] = freeze i8 [[X]]
; CHECK-NEXT: [[ARG2_FR:%.*]] = freeze i8 [[ARG2]]
; CHECK-NEXT: [[ARG_FR:%.*]] = freeze i8 [[ARG]]
; CHECK-NEXT: [[X_FR:%.*]] = urem i8 [[ARG_FR]], [[ARG2_FR]]
; CHECK-NEXT: [[ADD:%.*]] = add i8 [[X_FR]], 1
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[ADD]], [[ARG2]]
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[ADD]], [[ARG2_FR]]
; CHECK-NEXT: [[OUT:%.*]] = select i1 [[TMP1]], i8 0, i8 [[ADD]]
; CHECK-NEXT: ret i8 [[OUT]]
;
Expand Down
Loading
Loading