Skip to content

Commit 10e8258

Browse files
committed
[InstCombine] Treat identical operands as one in pushFreezeToPreventPoisonFromPropagating
To push a freeze through an instruction, only one operand may produce poison. However, this currently fails for identical operands which are treated as separate. This patch fixes this by treating them as a single operand.
1 parent 97d3aec commit 10e8258

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4902,7 +4902,9 @@ InstCombinerImpl::pushFreezeToPreventPoisonFromPropagating(FreezeInst &OrigFI) {
49024902
Use *MaybePoisonOperand = nullptr;
49034903
for (Use &U : OrigOpInst->operands()) {
49044904
if (isa<MetadataAsValue>(U.get()) ||
4905-
isGuaranteedNotToBeUndefOrPoison(U.get()))
4905+
isGuaranteedNotToBeUndefOrPoison(U.get()) ||
4906+
// Treat identical operands as a single operand.
4907+
(MaybePoisonOperand && MaybePoisonOperand->get() == U.get()))
49064908
continue;
49074909
if (!MaybePoisonOperand)
49084910
MaybePoisonOperand = &U;

llvm/test/Transforms/InstCombine/freeze.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ define i32 @early_freeze_test3(i32 %v1) {
144144

145145
define i32 @early_freeze_test4(i32 %v1) {
146146
; CHECK-LABEL: @early_freeze_test4(
147-
; CHECK-NEXT: [[V2:%.*]] = mul i32 [[V1_FR:%.*]], [[V1_FR]]
148-
; CHECK-NEXT: [[V2_FR:%.*]] = freeze i32 [[V2]]
149-
; CHECK-NEXT: ret i32 [[V2_FR]]
147+
; CHECK-NEXT: [[V2_FR:%.*]] = freeze i32 [[V2:%.*]]
148+
; CHECK-NEXT: [[V3:%.*]] = mul i32 [[V2_FR]], [[V2_FR]]
149+
; CHECK-NEXT: ret i32 [[V3]]
150150
;
151151
%v2 = mul i32 %v1, %v1
152152
%v2.fr = freeze i32 %v2

0 commit comments

Comments
 (0)