Skip to content

Commit e2ef66f

Browse files
committed
[HLSL] prevent phi codgen of isTokenLike types
fixes #161754 When the GVN pass is PerformLoadPRE we need to check if it might be doing this load on a token like type. This is because if we don't GVN will use the SSAUpdater to insert a phi node to reduce duplicate resource.getpointer calls. Because in an earlier commit: 01c0a84 we made the verifier error with `PHI nodes cannot have token type!` This test case will fail today if we try to perform this load optimization https://godbolt.org/z/xM69fY8zM
1 parent c7d776b commit e2ef66f

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,9 @@ bool GVNPass::PerformLoadPRE(LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
16591659
// that we only have to insert *one* load (which means we're basically moving
16601660
// the load, not inserting a new one).
16611661

1662+
if (Load->getType()->isTokenLikeTy())
1663+
return false;
1664+
16621665
SmallPtrSet<BasicBlock *, 4> Blockers(llvm::from_range, UnavailableBlocks);
16631666

16641667
// Let's find the first basic block with more than one predecessor. Walk
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
2+
; RUN: opt -S -passes=gvn %s | FileCheck %s
3+
4+
; NOTE: A test to confirm GVN doesn't introduce phis for pre loads of token
5+
; NOTE: like types. This implies the CHECKS should exactly match the IR.
6+
7+
define ptr @main() {
8+
; CHECK-LABEL: define ptr @main() {
9+
; CHECK-NEXT: [[ENTRY:.*:]]
10+
; CHECK-NEXT: br i1 false, label %[[ENTRY_IF_END_I_CRIT_EDGE:.*]], label %[[IF_THEN_I:.*]]
11+
; CHECK: [[ENTRY_IF_END_I_CRIT_EDGE]]:
12+
; CHECK-NEXT: br label %[[IF_END_I:.*]]
13+
; CHECK: [[IF_THEN_I]]:
14+
; CHECK-NEXT: [[TMP0:%.*]] = load target("dx.RawBuffer", half, 1, 0), ptr null, align 4
15+
; CHECK-NEXT: [[TMP1:%.*]] = tail call ptr @llvm.dx.resource.getpointer.p0.tdx.RawBuffer_f16_1_0t(target("dx.RawBuffer", half, 1, 0) [[TMP0]], i32 0)
16+
; CHECK-NEXT: br label %[[IF_END_I]]
17+
; CHECK: [[IF_END_I]]:
18+
; CHECK-NEXT: [[TMP2:%.*]] = load target("dx.RawBuffer", half, 1, 0), ptr null, align 4
19+
; CHECK-NEXT: [[TMP3:%.*]] = tail call ptr @llvm.dx.resource.getpointer.p0.tdx.RawBuffer_f16_1_0t(target("dx.RawBuffer", half, 1, 0) [[TMP2]], i32 0)
20+
; CHECK-NEXT: ret ptr [[TMP3]]
21+
;
22+
entry:
23+
br i1 false, label %if.end.i, label %if.then.i
24+
25+
if.then.i: ; preds = %entry
26+
%0 = load target("dx.RawBuffer", half, 1, 0), ptr null, align 4
27+
%1 = tail call ptr @llvm.dx.resource.getpointer.p0.tdx.RawBuffer_f16_1_0t(target("dx.RawBuffer", half, 1, 0) %0, i32 0)
28+
br label %if.end.i
29+
30+
if.end.i: ; preds = %if.then.i, %entry
31+
%2 = load target("dx.RawBuffer", half, 1, 0), ptr null, align 4
32+
%3 = tail call ptr @llvm.dx.resource.getpointer.p0.tdx.RawBuffer_f16_1_0t(target("dx.RawBuffer", half, 1, 0) %2, i32 0)
33+
ret ptr %3
34+
}

0 commit comments

Comments
 (0)