Skip to content

Commit f071efe

Browse files
committed
[InstSimplify] Don't simplify a multi-use freeze in simplifyWithOpReplaced
1 parent 6d3f317 commit f071efe

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4312,6 +4312,10 @@ static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
43124312
if (match(I, m_Intrinsic<Intrinsic::is_constant>()))
43134313
return nullptr;
43144314

4315+
// Don't simplify a use of a multi-use freeze.
4316+
if (isa<FreezeInst>(I) && !I->hasOneUse())
4317+
return nullptr;
4318+
43154319
// Replace Op with RepOp in instruction operands.
43164320
SmallVector<Value *, 8> NewOps;
43174321
bool AnyReplaced = false;

llvm/test/Transforms/InstCombine/select.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4586,7 +4586,9 @@ define i8 @test_replace_freeze_multiuse(i1 %x, i8 %y) {
45864586
; CHECK-NEXT: [[EXT:%.*]] = zext i1 [[X:%.*]] to i8
45874587
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i8 [[EXT]], [[Y:%.*]]
45884588
; CHECK-NEXT: [[SHL_FR:%.*]] = freeze i8 [[SHL]]
4589-
; CHECK-NEXT: ret i8 [[SHL_FR]]
4589+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X]], i8 0, i8 [[SHL_FR]]
4590+
; CHECK-NEXT: [[ADD:%.*]] = add i8 [[SHL_FR]], [[SEL]]
4591+
; CHECK-NEXT: ret i8 [[ADD]]
45904592
;
45914593
%ext = zext i1 %x to i8
45924594
%shl = shl nuw i8 %ext, %y

0 commit comments

Comments
 (0)