Skip to content

Commit 2d1801f

Browse files
committed
legalize freeze by removing it
1 parent 27dca03 commit 2d1801f

File tree

2 files changed

+1
-118
lines changed

2 files changed

+1
-118
lines changed

llvm/lib/Target/DirectX/DXILLegalizePass.cpp

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,54 +21,6 @@
2121

2222
using namespace llvm;
2323

24-
// The goal here will be to emulate freeze by Forcing SSA materialization.
25-
// We will do this by making the input bound to a real SSA value,
26-
// not a symbolic poison or undef. The implementation creates a dummy
27-
// control-flow split that always takes PathA and forces the inputs
28-
// through a phi node. Creating a dimond CFG makes the compiler
29-
// commit to one value for the input.
30-
// entry(%x)
31-
// |
32-
// +---+---+
33-
// | |
34-
// pathA(%x) pathB(%x)
35-
// | |
36-
// \______/
37-
// |
38-
// merge
39-
// %frozen = phi [ %x, %pathA ], [ %x, %pathB ]
40-
41-
static void lowerFreeze(FreezeInst *FI) {
42-
Type *Ty = FI->getType();
43-
LLVMContext &Ctx = FI->getContext();
44-
BasicBlock *OrigBB = FI->getParent();
45-
Value *Input = FI->getOperand(0);
46-
Function *F = FI->getFunction();
47-
48-
// Split the block to isolate the freeze instruction
49-
BasicBlock *MergeBB = OrigBB->splitBasicBlock(FI->getNextNode(), "merge");
50-
51-
// Remove the unconditional branch inserted by splitBasicBlock
52-
OrigBB->getTerminator()->eraseFromParent();
53-
BasicBlock *PathA = BasicBlock::Create(Ctx, "pathA", F, MergeBB);
54-
BasicBlock *PathB = BasicBlock::Create(Ctx, "pathB", F, MergeBB);
55-
56-
IRBuilder<> Builder(OrigBB);
57-
Builder.CreateCondBr(ConstantInt::getTrue(Ctx), PathA, PathB);
58-
59-
IRBuilder<> BuilderA(PathA);
60-
BuilderA.CreateBr(MergeBB);
61-
IRBuilder<> BuilderB(PathB);
62-
BuilderB.CreateBr(MergeBB);
63-
64-
IRBuilder<> BuilderMerge(&MergeBB->front());
65-
PHINode *Phi = BuilderMerge.CreatePHI(Ty, 2, "frozen");
66-
Phi->addIncoming(Input, PathA);
67-
Phi->addIncoming(Input, PathB);
68-
69-
FI->replaceAllUsesWith(Phi);
70-
}
71-
7224
static void legalizeFreeze(Instruction &I,
7325
SmallVectorImpl<Instruction *> &ToRemove,
7426
DenseMap<Value *, Value *>) {
@@ -77,12 +29,7 @@ static void legalizeFreeze(Instruction &I,
7729
return;
7830

7931
Value *Input = FI->getOperand(0);
80-
81-
if (isGuaranteedNotToBeUndefOrPoison(Input))
82-
FI->replaceAllUsesWith(Input);
83-
else
84-
lowerFreeze(FI);
85-
32+
FI->replaceAllUsesWith(Input);
8633
ToRemove.push_back(FI);
8734
}
8835

llvm/test/CodeGen/DirectX/legalize-freeze.ll

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7,74 +7,10 @@ define i32 @test_remove_freeze(i32 %x) {
77
; CHECK-LABEL: define i32 @test_remove_freeze(
88
; CHECK-SAME: i32 [[X:%.*]]) {
99
; CHECK-NEXT: [[ENTRY:.*:]]
10-
; CHECK-NEXT: br i1 true, label %[[PATHA:.*]], label %[[PATHB:.*]]
11-
; CHECK: [[PATHA]]:
12-
; CHECK-NEXT: br label %[[MERGE:.*]]
13-
; CHECK: [[PATHB]]:
14-
; CHECK-NEXT: br label %[[MERGE]]
15-
; CHECK: [[MERGE]]:
16-
; CHECK-NEXT: [[FROZEN:%.*]] = phi i32 [ [[X]], %[[PATHA]] ], [ [[X]], %[[PATHB]] ]
17-
; CHECK-NEXT: [[Y:%.*]] = add i32 [[FROZEN]], 1
18-
; CHECK-NEXT: ret i32 [[Y]]
19-
;
20-
entry:
21-
%f = freeze i32 %x
22-
%y = add i32 %f, 1
23-
ret i32 %y
24-
}
25-
26-
define i32 @test_remove_freeze_safe(i32 %x) {
27-
; CHECK-LABEL: define i32 @test_remove_freeze_safe(
28-
; CHECK-SAME: i32 [[X:%.*]]) {
29-
; CHECK-NEXT: [[ENTRY:.*:]]
30-
; CHECK-NEXT: [[FROZEN:%.*]] = add i32 1, 0
31-
; CHECK-NEXT: [[Y:%.*]] = add i32 [[FROZEN]], 1
32-
; CHECK-NEXT: ret i32 [[Y]]
33-
;
34-
entry:
35-
%safe = add i32 1, 0
36-
%f = freeze i32 %safe
37-
%y = add i32 %f, 1
38-
ret i32 %y
39-
}
40-
41-
define i32 @test_freeze_poison() {
42-
; CHECK-LABEL: define i32 @test_freeze_poison() {
43-
; CHECK-NEXT: [[ENTRY:.*:]]
44-
; CHECK-NEXT: [[X1:%.*]] = select i1 true, i32 42, i32 poison
45-
; CHECK-NEXT: br i1 true, label %[[PATHA:.*]], label %[[PATHB:.*]]
46-
; CHECK: [[PATHA]]:
47-
; CHECK-NEXT: br label %[[MERGE:.*]]
48-
; CHECK: [[PATHB]]:
49-
; CHECK-NEXT: br label %[[MERGE]]
50-
; CHECK: [[MERGE]]:
51-
; CHECK-NEXT: [[X:%.*]] = phi i32 [ [[X1]], %[[PATHA]] ], [ [[X1]], %[[PATHB]] ]
5210
; CHECK-NEXT: [[Y:%.*]] = add i32 [[X]], 1
5311
; CHECK-NEXT: ret i32 [[Y]]
5412
;
5513
entry:
56-
%x = select i1 true, i32 42, i32 poison
57-
%f = freeze i32 %x
58-
%y = add i32 %f, 1
59-
ret i32 %y
60-
}
61-
62-
define i32 @test_freeze_undef() {
63-
; CHECK-LABEL: define i32 @test_freeze_undef() {
64-
; CHECK-NEXT: [[ENTRY:.*:]]
65-
; CHECK-NEXT: [[X:%.*]] = select i1 undef, i32 42, i32 2
66-
; CHECK-NEXT: br i1 true, label %[[PATHA:.*]], label %[[PATHB:.*]]
67-
; CHECK: [[PATHA]]:
68-
; CHECK-NEXT: br label %[[MERGE:.*]]
69-
; CHECK: [[PATHB]]:
70-
; CHECK-NEXT: br label %[[MERGE]]
71-
; CHECK: [[MERGE]]:
72-
; CHECK-NEXT: [[FROZEN:%.*]] = phi i32 [ [[X]], %[[PATHA]] ], [ [[X]], %[[PATHB]] ]
73-
; CHECK-NEXT: [[Y:%.*]] = add i32 [[FROZEN]], 1
74-
; CHECK-NEXT: ret i32 [[Y]]
75-
;
76-
entry:
77-
%x = select i1 undef, i32 42, i32 2
7814
%f = freeze i32 %x
7915
%y = add i32 %f, 1
8016
ret i32 %y

0 commit comments

Comments
 (0)