Skip to content

Commit a9ee464

Browse files
KorovinVladigcbot
authored andcommitted
Fix PHI category conversion placement
.
1 parent 1dc09d7 commit a9ee464

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXCategory.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,16 @@ namespace {
347347

348348
void placeConvAfterDef(Function *Func, Instruction *Conv, Value *Def) {
349349
if (Instruction *Inst = dyn_cast<Instruction>(Def)) {
350+
if (isa<PHINode>(Inst)) {
351+
// Original value is a PHI. Inserting conversion right after it can
352+
// produce incorrect IR in case of several PHI nodes since they must be
353+
// grouped at top of basic block. So insert the conversion after all PHI
354+
// nodes.
355+
auto *FirstNonPhiInst = Inst->getParent()->getFirstNonPHI();
356+
Conv->insertBefore(FirstNonPhiInst);
357+
Conv->setDebugLoc(Inst->getDebugLoc());
358+
return;
359+
}
350360
// Original value is an instruction. Insert just after it.
351361
Conv->insertAfter(Inst);
352362
Conv->setDebugLoc(Inst->getDebugLoc());
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2023 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; RUN: %opt %use_old_pass_manager% -GenXModule -GenXNumberingWrapper -GenXLiveRangesWrapper -GenXCategoryWrapper \
10+
; RUN: -march=genx64 -mtriple=spir64-unknown-unknown -mcpu=Gen9 -S < %s | FileCheck %s
11+
12+
declare void @llvm.genx.oword.st.v8f32(i32, i32, <8 x float>) #0
13+
declare !genx_intrinsic_id !17 i16 @llvm.genx.rdregioni.i16.v3i16.i16(<3 x i16>, i32, i32, i32, i16, i32) #1
14+
15+
define dllexport spir_kernel void @kernel(<3 x i16> %impl.arg.llvm.genx.local.id16, i64 %impl.arg.private.base) local_unnamed_addr #2 {
16+
entry:
17+
%rdregioni = call i16 @llvm.genx.rdregioni.i16.v3i16.i16(<3 x i16> %impl.arg.llvm.genx.local.id16, i32 0, i32 1, i32 1, i16 0, i32 0)
18+
%tobool.not = icmp eq i16 %rdregioni, 0
19+
br i1 %tobool.not, label %if, label %if.end
20+
21+
if:
22+
br label %if.end
23+
24+
if.end:
25+
; CHECK: %.dst.1 = phi i32
26+
; CHECK-NEXT: %.dst.2 = phi i32
27+
; CHECK-NEXT: call i32 @llvm.genx.convert
28+
; CHECK-NEXT: call i32 @llvm.genx.convert
29+
%.dst.1 = phi i32 [ 4, %if ], [ 7, %entry ]
30+
%.dst.2 = phi i32 [ 2, %if ], [ 5, %entry ]
31+
tail call void @llvm.genx.oword.st.v8f32(i32 %.dst.1, i32 0, <8 x float> zeroinitializer)
32+
tail call void @llvm.genx.oword.st.v8f32(i32 %.dst.2, i32 0, <8 x float> zeroinitializer)
33+
ret void
34+
}
35+
36+
attributes #0 = { nounwind }
37+
attributes #1 = { nounwind readnone }
38+
attributes #2 = { noinline nounwind "CMGenxMain" "oclrt"="1" }
39+
40+
!genx.kernels = !{!6}
41+
!genx.kernel.internal = !{!13}
42+
43+
!4 = !{}
44+
!6 = !{void (<3 x i16>, i64)* @kernel, !"kernel", !7, i32 0, !8, !9, !10, i32 0}
45+
!7 = !{i32 24, i32 96}
46+
!8 = !{i32 32, i32 64}
47+
!9 = !{i32 0, i32 0}
48+
!10 = !{!""}
49+
!13 = !{void (<3 x i16>, i64)* @kernel, !14, !15, !4, !16}
50+
!14 = !{i32 0, i32 0}
51+
!15 = !{i32 7, i32 8}
52+
!16 = !{i32 255, i32 255}
53+
!17 = !{i32 10973}

0 commit comments

Comments
 (0)