Skip to content

Commit 9f8bf2f

Browse files
mshelegoigcbot
authored andcommitted
Const breaker fix for PHI nodes
Prevent const breaker from inserting instructions before PHI nodes. Insert them in the end of incoming block instead
1 parent 65480d4 commit 9f8bf2f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

IGC/VectorCompiler/lib/Utils/GenX/BreakConst.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ bool vc::breakConstantExprs(Instruction *I,
146146
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Op)) {
147147
Instruction *NewInst = CE->getAsInstruction();
148148
NewInst->setDebugLoc(CurInst->getDebugLoc());
149-
NewInst->insertBefore(CurInst);
149+
NewInst->insertBefore(InsertPt);
150150
CurInst->setOperand(i, NewInst);
151151
Worklist.push_back(NewInst);
152152
Modified = true;

IGC/VectorCompiler/test/PostLegalization/const_breaker_legalized.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,25 @@ define <2 x i8*> @test_constexpr_ptrvect() {
7373
%data = call <2 x i8*> @llvm.genx.rdregioni.v2p0i8.v2p0i8.i16(<2 x i8*> <i8 addrspace(0)* inttoptr (i32 2 to i8 addrspace(0)*), i8 addrspace(0)* inttoptr (i32 1 to i8 addrspace(0)*)>, i32 0, i32 1, i32 1, i16 0, i32 undef)
7474
ret <2 x i8*> %data
7575
}
76+
77+
; CHECK-LABEL: @test_constexpr_phi
78+
; CHECK-NEXT: BB1:
79+
; CHECK-NEXT: [[PTRCAST1:%[^ ]+]] = inttoptr i32 1 to i8*
80+
; CHECK-NEXT: br i1 %cond, label %BB2, label %BB3
81+
; CHECK: BB2:
82+
; CHECK-NEXT: [[PTRCAST2:%[^ ]+]] = inttoptr i32 2 to i8*
83+
; CHECK-NEXT: br label %BB3
84+
; CHECK: BB3:
85+
; CHECK-NEXT: [[RESULT:%[^ ]+]] = phi i8* [ [[PTRCAST1]], %BB1 ], [ [[PTRCAST2]], %BB2 ]
86+
; CHECK-NEXT: ret i8* [[RESULT]]
87+
define i8* @test_constexpr_phi(i1 %cond) {
88+
BB1:
89+
br i1 %cond, label %BB2, label %BB3
90+
91+
BB2:
92+
br label %BB3
93+
94+
BB3:
95+
%phi = phi i8* [ inttoptr (i32 1 to i8 addrspace(0)*), %BB1 ], [ inttoptr (i32 2 to i8 addrspace(0)*), %BB2 ]
96+
ret i8* %phi
97+
}

0 commit comments

Comments
 (0)