Revert "[InstCombine] Allow freezing multiple operands (#154336)"#182769
Merged
Conversation
Member
|
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-pgo Author: Eli Friedman (efriedma-quic) ChangesThis reverts commit f8f6965. This is causing infinte loops interacting with other transforms. See discussion on #182647 . Patch is 30.77 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/182769.diff 13 Files Affected:
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index fd699381c22fa..1208f5d1e41b9 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -5199,68 +5199,63 @@ 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 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...)
+ // 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
// ... = Freeze(Op0)
// =>
// Op1 = ...
// Op1.fr = Freeze(Op1)
// ... = Inst(Op1.fr, NonPoisonOps...)
+ auto *OrigOp = OrigFI.getOperand(0);
+ auto *OrigOpInst = dyn_cast<Instruction>(OrigOp);
- 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.)
- return !canCreateUndefOrPoison(cast<Operator>(V),
- /*ConsiderFlagsAndMetadata*/ false);
- };
+ // 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;
- // 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;
+ // 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;
- auto *UserI = cast<Instruction>(U->getUser());
- Builder.SetInsertPoint(UserI);
- Value *Frozen = Builder.CreateFreeze(V, V->getName() + ".fr");
- U->set(Frozen);
+ // 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))
continue;
- }
+ if (!MaybePoisonOperand)
+ MaybePoisonOperand = V;
+ else
+ return nullptr;
+ }
- auto *I = cast<Instruction>(V);
- if (!Visited.insert(I).second)
- continue;
+ OrigOpInst->dropPoisonGeneratingAnnotations();
- // 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);
- }
+ // If all operands are guaranteed to be non-poison, we can drop freeze.
+ if (!MaybePoisonOperand)
+ return OrigOp;
- I->dropPoisonGeneratingAnnotations();
- this->Worklist.add(I);
- }
+ Builder.SetInsertPoint(OrigOpInst);
+ Value *FrozenMaybePoisonOperand = Builder.CreateFreeze(
+ MaybePoisonOperand, MaybePoisonOperand->getName() + ".fr");
- return OrigUse->get();
+ OrigOpInst->replaceUsesOfWith(MaybePoisonOperand, FrozenMaybePoisonOperand);
+ return OrigOp;
}
Instruction *InstCombinerImpl::foldFreezeIntoRecurrence(FreezeInst &FI,
diff --git a/llvm/test/Transforms/InstCombine/freeze-fp-ops.ll b/llvm/test/Transforms/InstCombine/freeze-fp-ops.ll
index b1c6fc05e864c..1caf7ec87016e 100644
--- a/llvm/test/Transforms/InstCombine/freeze-fp-ops.ll
+++ b/llvm/test/Transforms/InstCombine/freeze-fp-ops.ll
@@ -163,9 +163,8 @@ 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: [[ARG0_FR:%.*]] = freeze float [[ARG0]]
-; CHECK-NEXT: [[ARG1_FR:%.*]] = freeze i32 [[ARG1]]
-; CHECK-NEXT: [[OP:%.*]] = call float @llvm.powi.f32.i32(float [[ARG0_FR]], i32 [[ARG1_FR]])
+; CHECK-NEXT: [[OP1:%.*]] = call float @llvm.powi.f32.i32(float [[ARG0]], i32 [[ARG1]])
+; CHECK-NEXT: [[OP:%.*]] = freeze float [[OP1]]
; CHECK-NEXT: ret float [[OP]]
;
%op = call float @llvm.powi.f32.i32(float %arg0, i32 %arg1)
diff --git a/llvm/test/Transforms/InstCombine/freeze.ll b/llvm/test/Transforms/InstCombine/freeze.ll
index 6ff13c005a999..80db307ff5e25 100644
--- a/llvm/test/Transforms/InstCombine/freeze.ll
+++ b/llvm/test/Transforms/InstCombine/freeze.ll
@@ -108,9 +108,8 @@ define <3 x i4> @partial_undef_vec() {
define i32 @early_freeze_test1(i32 %x, i32 %y) {
; CHECK-LABEL: define i32 @early_freeze_test1(
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
-; 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: [[V4:%.*]] = add i32 [[X]], [[Y]]
+; CHECK-NEXT: [[V1:%.*]] = freeze i32 [[V4]]
; CHECK-NEXT: [[V2:%.*]] = shl i32 [[V1]], 1
; CHECK-NEXT: [[V3:%.*]] = and i32 [[V2]], 2
; CHECK-NEXT: ret i32 [[V3]]
@@ -944,14 +943,14 @@ 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: [[TMP0:%.*]] = freeze ptr [[INIT]]
; CHECK-NEXT: br label %[[LOOP:.*]]
; CHECK: [[LOOP]]:
-; CHECK-NEXT: [[I:%.*]] = phi ptr [ [[TMP0]], %[[ENTRY]] ], [ [[I_NEXT:%.*]], %[[LOOP]] ]
+; CHECK-NEXT: [[I:%.*]] = phi ptr [ [[INIT]], %[[ENTRY]] ], [ [[I_NEXT_FR:%.*]], %[[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: [[COND:%.*]] = icmp eq ptr [[I_NEXT]], [[END]]
+; 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: ret void
@@ -978,13 +977,13 @@ define void @fold_phi_gep_inbounds_phi_offset(ptr %init, ptr %end, i64 noundef %
; CHECK-LABEL: define void @fold_phi_gep_inbounds_phi_offset(
; CHECK-SAME: ptr [[INIT:%.*]], ptr [[END:%.*]], i64 noundef [[N:%.*]]) {
; 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: [[I:%.*]] = phi ptr [ [[INIT]], %[[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_NEXT1:%.*]] = getelementptr inbounds i8, ptr [[I]], i64 [[OFF_NEXT]]
+; CHECK-NEXT: [[I_NEXT]] = freeze ptr [[I_NEXT1]]
; CHECK-NEXT: [[COND:%.*]] = icmp eq ptr [[I_NEXT]], [[END]]
; CHECK-NEXT: br i1 [[COND]], label %[[LOOP]], label %[[EXIT:.*]]
; CHECK: [[EXIT]]:
@@ -1011,14 +1010,13 @@ define void @fold_phi_gep_phi_offset_multiple(ptr %init, ptr %end, i64 %n) {
; CHECK-LABEL: define void @fold_phi_gep_phi_offset_multiple(
; CHECK-SAME: ptr [[INIT:%.*]], ptr [[END:%.*]], i64 [[N:%.*]]) {
; 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: [[I:%.*]] = phi ptr [ [[INIT]], %[[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_NEXT1:%.*]] = getelementptr inbounds i8, ptr [[I]], i64 [[OFF_NEXT]]
+; CHECK-NEXT: [[I_NEXT]] = freeze ptr [[I_NEXT1]]
; CHECK-NEXT: [[COND:%.*]] = icmp eq ptr [[I_NEXT]], [[END]]
; CHECK-NEXT: br i1 [[COND]], label %[[LOOP]], label %[[EXIT:.*]]
; CHECK: [[EXIT]]:
@@ -1671,13 +1669,13 @@ define i32 @pr171435_2(ptr noundef %arg, i32 noundef %arg1) "instcombine-no-veri
; CHECK: [[BB_7]]:
; CHECK-NEXT: br label %[[BB_8]]
; CHECK: [[BB_8]]:
-; CHECK-NEXT: [[PHI9:%.*]] = phi i32 [ [[CALL6]], %[[BB_5]] ], [ poison, %[[BB_7]] ]
-; CHECK-NEXT: [[PHI9_FR:%.*]] = freeze i32 [[PHI9]]
+; CHECK-NEXT: [[PHI9_FR:%.*]] = phi i32 [ [[CALL6]], %[[BB_5]] ], [ poison, %[[BB_7]] ]
; CHECK-NEXT: [[AND:%.*]] = and i32 [[PHI9_FR]], 1
; CHECK-NEXT: [[ASHR:%.*]] = lshr i32 [[PHI9_FR]], 1
; CHECK-NEXT: [[ADD:%.*]] = add nuw i32 [[ASHR]], [[AND]]
; CHECK-NEXT: [[ADD10:%.*]] = add i32 [[PHI]], [[ADD]]
-; CHECK-NEXT: [[AND11:%.*]] = and i32 [[ADD10]], 255
+; CHECK-NEXT: [[ADD10_FR:%.*]] = freeze i32 [[ADD10]]
+; CHECK-NEXT: [[AND11:%.*]] = and i32 [[ADD10_FR]], 255
; CHECK-NEXT: [[ICMP12:%.*]] = icmp eq i32 [[AND11]], 0
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[ICMP12]], i32 [[PHI]], i32 [[AND11]]
; CHECK-NEXT: br label %[[BB_13]]
diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll
index 42a09420769f4..a6ad6f59dc0ec 100644
--- a/llvm/test/Transforms/InstCombine/icmp.ll
+++ b/llvm/test/Transforms/InstCombine/icmp.ll
@@ -5835,9 +5835,10 @@ 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: [[Y_FR:%.*]] = freeze i16 [[Y]]
-; CHECK-NEXT: [[X_FR:%.*]] = freeze i16 [[X]]
-; CHECK-NEXT: [[CMP2:%.*]] = icmp uge i16 [[X_FR]], [[Y_FR]]
+; 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: ret i1 [[CMP2]]
;
%cmp1 = icmp uge i16 %x, %y
diff --git a/llvm/test/Transforms/InstCombine/nsw.ll b/llvm/test/Transforms/InstCombine/nsw.ll
index 4615ac0ec1ffb..b00f2e58add78 100644
--- a/llvm/test/Transforms/InstCombine/nsw.ll
+++ b/llvm/test/Transforms/InstCombine/nsw.ll
@@ -255,10 +255,9 @@ 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: [[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]]
+; CHECK-NEXT: [[A_NEG:%.*]] = sub nsw i8 [[A2:%.*]], [[A1:%.*]]
+; CHECK-NEXT: [[FR_NEG:%.*]] = freeze i8 [[A_NEG]]
+; CHECK-NEXT: ret i8 [[FR_NEG]]
;
%a = sub nsw i8 %a1, %a2
%fr = freeze i8 %a
diff --git a/llvm/test/Transforms/InstCombine/select-gep.ll b/llvm/test/Transforms/InstCombine/select-gep.ll
index 718133699a8a7..79287fd933cc0 100644
--- a/llvm/test/Transforms/InstCombine/select-gep.ll
+++ b/llvm/test/Transforms/InstCombine/select-gep.ll
@@ -304,10 +304,9 @@ define ptr @ptr_eq_replace_freeze1(ptr %p, ptr %q) {
define ptr @ptr_eq_replace_freeze2(ptr %p, ptr %q) {
; CHECK-LABEL: @ptr_eq_replace_freeze2(
-; CHECK-NEXT: [[P_FR:%.*]] = freeze ptr [[P:%.*]]
-; CHECK-NEXT: [[P_FR1:%.*]] = freeze ptr [[P1:%.*]]
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[P_FR1]], [[P_FR]]
-; CHECK-NEXT: [[SELECT_V:%.*]] = select i1 [[CMP]], ptr [[P_FR1]], ptr [[P_FR]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[P_FR1:%.*]], [[P_FR:%.*]]
+; CHECK-NEXT: [[CMP_FR:%.*]] = freeze i1 [[CMP]]
+; CHECK-NEXT: [[SELECT_V:%.*]] = select i1 [[CMP_FR]], ptr [[P_FR1]], ptr [[P_FR]]
; CHECK-NEXT: [[SELECT:%.*]] = getelementptr i8, ptr [[SELECT_V]], i64 16
; CHECK-NEXT: ret ptr [[SELECT]]
;
diff --git a/llvm/test/Transforms/InstCombine/select.ll b/llvm/test/Transforms/InstCombine/select.ll
index 6076a18b6501c..d76b6dc489712 100644
--- a/llvm/test/Transforms/InstCombine/select.ll
+++ b/llvm/test/Transforms/InstCombine/select.ll
@@ -2847,8 +2847,10 @@ define void @cond_freeze_multipleuses(i8 %x, i8 %y) {
define i32 @select_freeze_icmp_eq(i32 %x, i32 %y) {
; CHECK-LABEL: define i32 @select_freeze_icmp_eq(
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
-; CHECK-NEXT: [[Y_FR:%.*]] = freeze i32 [[Y]]
-; CHECK-NEXT: ret i32 [[Y_FR]]
+; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X]], [[Y]]
+; CHECK-NEXT: [[C_FR:%.*]] = freeze i1 [[C]]
+; CHECK-NEXT: [[V:%.*]] = select i1 [[C_FR]], i32 [[X]], i32 [[Y]]
+; CHECK-NEXT: ret i32 [[V]]
;
%c = icmp eq i32 %x, %y
%c.fr = freeze i1 %c
@@ -2859,8 +2861,10 @@ 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: [[X_FR:%.*]] = freeze i32 [[X]]
-; CHECK-NEXT: ret i32 [[X_FR]]
+; 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: ret i32 [[V]]
;
%c = icmp ne i32 %x, %y
%c.fr = freeze i1 %c
@@ -2871,9 +2875,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: [[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: [[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: ret i32 [[V]]
;
%c = icmp ult i32 %x, %y
@@ -2887,9 +2891,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: [[Y_FR:%.*]] = freeze i32 [[Y]]
-; CHECK-NEXT: [[V:%.*]] = freeze i32 [[X]]
-; CHECK-NEXT: [[C_FR:%.*]] = icmp ne i32 [[V]], [[Y_FR]]
+; 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: call void @use_i1_i32(i1 [[C_FR]], i32 [[V]])
; CHECK-NEXT: ret void
;
diff --git a/llvm/test/Transforms/InstCombine/sub-of-negatible-inseltpoison.ll b/llvm/test/Transforms/InstCombine/sub-of-negatible-inseltpoison.ll
index 109669e91d22f..537497110cd8a 100644
--- a/llvm/test/Transforms/InstCombine/sub-of-negatible-inseltpoison.ll
+++ b/llvm/test/Transforms/InstCombine/sub-of-negatible-inseltpoison.ll
@@ -1446,9 +1446,8 @@ 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: [[X_FR:%.*]] = freeze i4 [[X]]
-; CHECK-NEXT: [[Y_FR:%.*]] = freeze i4 [[Y]]
-; CHECK-NEXT: [[T1_NEG:%.*]] = sub i4 [[Y_FR]], [[X_FR]]
+; CHECK-NEXT: [[T0_NEG:%.*]] = sub i4 [[Y]], [[X]]
+; CHECK-NEXT: [[T1_NEG:%.*]] = freeze i4 [[T0_NEG]]
; CHECK-NEXT: [[T2:%.*]] = add i4 [[T1_NEG]], [[Z]]
; CHECK-NEXT: ret i4 [[T2]]
;
@@ -1460,9 +1459,8 @@ 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: [[X_FR:%.*]] = freeze i4 [[X]]
-; CHECK-NEXT: [[Y_FR:%.*]] = freeze i4 [[Y]]
-; CHECK-NEXT: [[T1:%.*]] = sub i4 [[X_FR]], [[Y_FR]]
+; CHECK-NEXT: [[T0:%.*]] = sub i4 [[X]], [[Y]]
+; CHECK-NEXT: [[T1:%.*]] = freeze i4 [[T0]]
; CHECK-NEXT: call void @use4(i4 [[T1]])
; CHECK-NEXT: [[T2:%.*]] = sub i4 [[Z]], [[T1]]
; CHECK-NEXT: ret i4 [[T2]]
diff --git a/llvm/test/Transforms/InstCombine/sub-of-negatible.ll b/llvm/test/Transforms/InstCombine/sub-of-negatible.ll
index aad006de0e361..3a91c14e8ba10 100644
--- a/llvm/test/Transforms/InstCombine/sub-of-negatible.ll
+++ b/llvm/test/Transforms/InstCombine/sub-of-negatible.ll
@@ -1543,9 +1543,8 @@ 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: [[X_FR:%.*]] = freeze i4 [[X]]
-; CHECK-NEXT: [[Y_FR:%.*]] = freeze i4 [[Y]]
-; CHECK-NEXT: [[T1_NEG:%.*]] = sub i4 [[Y_FR]], [[X_FR]]
+; CHECK-NEXT: [[T0_NEG:%.*]] = sub i4 [[Y]], [[X]]
+; CHECK-NEXT: [[T1_NEG:%.*]] = freeze i4 [[T0_NEG]]
; CHECK-NEXT: [[T2:%.*]] = add i4 [[T1_NEG]], [[Z]]
; CHECK-NEXT: ret i4 [[T2]]
;
@@ -1557,9 +1556,8 @@ 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: [[X_FR:%.*]] = freeze i4 [[X]]
-; CHECK-NEXT: [[Y_FR:%.*]] = freeze i4 [[Y]]
-; CHECK-NEXT: [[T1:%.*]] = sub i4 [[X_FR]], [[Y_FR]]
+; CHECK-NEXT: [[T0:%.*]] = sub i4 [[X]], [[Y]]
+; CHECK-NEXT: [[T1:%.*]] = freeze i4 [[T0]]
; CHECK-NEXT: call void @use4(i4 [[T1]])
; CHECK-NEXT: [[T2:%.*]] = sub i4 [[Z]], [[T1]]
; CHECK-NEXT: ret i4 [[T2]]
diff --git a/llvm/test/Transforms/InstCombine/urem-via-cmp-select.ll b/llvm/test/Transforms/InstCombine/urem-via-cmp-select.ll
index 16981d0a39ad2..c74c37fa8facb 100644
--- a/llvm/test/Transforms/InstCombine/urem-via-cmp-select.ll
+++ b/llvm/test/Transforms/InstCombine/urem-via-cmp-select.ll
@@ -96,11 +96,10 @@ 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-S...
[truncated]
|
nikic
approved these changes
Feb 22, 2026
This reverts commit f8f6965. This is causing infinte loops interacting with other transforms. See discussion on llvm#182647 .
e2007fa to
bec98ed
Compare
Contributor
Author
|
/cherry-pick bd3b163 |
Member
|
Failed to cherry-pick: bd3b163 Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request |
c-rhodes
pushed a commit
to efriedma-quic/llvm-project
that referenced
this pull request
Feb 23, 2026
…llvm#182769) This reverts commit f8f6965. This is causing infinite loops interacting with other transforms. See discussion on llvm#182647 . (cherry picked from commit bd3b163)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This reverts commit f8f6965.
This is causing infinte loops interacting with other transforms. See discussion on #182647 .