Skip to content

[InstCombine] Treat identical operands as one in pushFreezeToPreventPoisonFromPropagating #145348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4774,7 +4774,9 @@ InstCombinerImpl::pushFreezeToPreventPoisonFromPropagating(FreezeInst &OrigFI) {
Use *MaybePoisonOperand = nullptr;
for (Use &U : OrigOpInst->operands()) {
if (isa<MetadataAsValue>(U.get()) ||
isGuaranteedNotToBeUndefOrPoison(U.get()))
isGuaranteedNotToBeUndefOrPoison(U.get()) ||
// Treat identical operands as a single operand.
(MaybePoisonOperand && MaybePoisonOperand->get() == U.get()))
continue;
if (!MaybePoisonOperand)
MaybePoisonOperand = &U;
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/Transforms/InstCombine/freeze.ll
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ define i32 @early_freeze_test3(i32 %v1) {
ret i32 %v4.fr
}

define i32 @early_freeze_test4(i32 %v1) {
; CHECK-LABEL: @early_freeze_test4(
; CHECK-NEXT: [[V2_FR:%.*]] = freeze i32 [[V2:%.*]]
; CHECK-NEXT: [[V3:%.*]] = mul i32 [[V2_FR]], [[V2_FR]]
; CHECK-NEXT: ret i32 [[V3]]
;
%v2 = mul i32 %v1, %v1
%v2.fr = freeze i32 %v2
ret i32 %v2.fr
}

; If replace all dominated uses of v to freeze(v).

define void @freeze_dominated_uses_test1(i32 %v) {
Expand Down
Loading