Skip to content

Commit ae382b7

Browse files
mmereckiigcbot
authored andcommitted
Fix pixel shader input sinking in CodeSinking
CodeSinking moves input intrinsics before their first uses in the target basic block. Phi instructions should not be treated as valid uses in the currect block as their use is actually in a predecessor block.
1 parent 2199209 commit ae382b7

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

IGC/Compiler/CISACodeGen/CodeSinking.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ static BasicBlock *findLowestSinkTarget(Instruction *inst, SmallPtrSetImpl<Instr
138138
break;
139139
}
140140
}
141+
141142
BasicBlock *curBlk = inst->getParent();
142143
Loop *curLoop = LI->getLoopFor(inst->getParent());
143144
while (tgtBlk && tgtBlk != curBlk) {
@@ -151,7 +152,7 @@ static BasicBlock *findLowestSinkTarget(Instruction *inst, SmallPtrSetImpl<Instr
151152
// Determine the block of the use.
152153
Instruction *useInst = cast<Instruction>(*I);
153154
BasicBlock *useBlock = useInst->getParent();
154-
if (useBlock == tgtBlk) {
155+
if (useBlock == tgtBlk && !isa<PHINode>(useInst)) {
155156
usesInBlk.insert(useInst);
156157
}
157158
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
;
2+
; Copyright (C) 2025 Intel Corporation
3+
;
4+
; This software and the related documents are Intel copyrighted materials,
5+
; and your use of them is governed by the express license under which they were
6+
; provided to you ("License"). Unless the License provides otherwise,
7+
; you may not use, modify, copy, publish, distribute, disclose or transmit this
8+
; software or the related documents without Intel's prior written permission.
9+
;
10+
; This software and the related documents are provided as is, with no express or
11+
; implied warranties, other than those that are expressly stated in the License.
12+
;
13+
;============================ end_copyright_notice =============================
14+
; REQUIRES: llvm-14-plus, regkeys
15+
; RUN: igc_opt --opaque-pointers --igc-code-sinking --regkey CodeSinkingMinSize=1 -S %s | FileCheck %s
16+
17+
;CHECK-LABEL: entry:
18+
;CHECK-NOT: @llvm.genx.GenISA.DCL.inputVec.f32
19+
;CHECK-LABEL: loop:
20+
;CHECK-NEXT: [[IN1:%.*]] = phi float [ 0.000000e+00, %preheader ], [ [[IN0:%.*]], %loop ]
21+
;CHECK: [[IN0]] = call float @llvm.genx.GenISA.DCL.inputVec.f32(i32 0, i32 2)
22+
;CHECK: br i1 [[CMP:%.*]], label %loop, label %afterloop
23+
24+
define float @foo(i32 %count) {
25+
26+
entry:
27+
%input = call float @llvm.genx.GenISA.DCL.inputVec.f32(i32 0, i32 2)
28+
br label %preheader
29+
30+
preheader:
31+
br label %loop
32+
33+
loop:
34+
%input1 = phi float [ 0.000000e+00, %preheader ], [ %input, %loop ]
35+
%index = phi i32 [ 0, %preheader ], [ %inc, %loop ]
36+
%cmptmp = icmp ult i32 %index, %count
37+
%inc = add i32 %index, 1
38+
br i1 %cmptmp, label %loop, label %afterloop
39+
40+
afterloop:
41+
%res = fadd float %input1, %input
42+
ret float %res
43+
}
44+
45+
declare float @llvm.genx.GenISA.DCL.inputVec.f32(i32, i32) #1
46+
47+
attributes #1 = { nounwind readnone willreturn }
48+
49+
!igc.functions = !{}
50+

0 commit comments

Comments
 (0)