Skip to content

Commit 9eb7f4f

Browse files
authored
Don't replace readfirstlane in GVN::propagateEquality. (#3504)
1 parent bece3d4 commit 9eb7f4f

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

lib/Transforms/Scalar/GVN.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "llvm/Transforms/Utils/SSAUpdater.h"
5353
#include <vector>
5454
#include "dxc/DXIL/DxilConstants.h" // HLSL Change
55+
#include "dxc/DXIL/DxilOperations.h" // HLSL Change
5556
using namespace llvm;
5657
using namespace PatternMatch;
5758

@@ -2127,6 +2128,15 @@ bool GVN::propagateEquality(Value *LHS, Value *RHS,
21272128
// LHS always has at least one use that is not dominated by Root, this will
21282129
// never do anything if LHS has only one use.
21292130
if (!LHS->hasOneUse()) {
2131+
// HLSL Change Begin - Don't replace readfirstlane to help propagate
2132+
// uniform info.
2133+
if (CallInst *CI = dyn_cast<CallInst>(LHS)) {
2134+
if (hlsl::OP::IsDxilOpFuncCallInst(
2135+
CI, hlsl::DXIL::OpCode::WaveReadLaneFirst)) {
2136+
continue;
2137+
}
2138+
}
2139+
// HLSL Change End
21302140
unsigned NumReplacements = replaceDominatedUsesWith(LHS, RHS, *DT, Root);
21312141
Changed |= NumReplacements > 0;
21322142
NumGVNEqProp += NumReplacements;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
2+
3+
//CHECK:%[[FirstLane:[a-zA-Z0-9]+]] = call i32 @dx.op.waveReadLaneFirst.i32(i32 118,
4+
// Make sure use FirstLane.
5+
//CHECK:uitofp i32 %[[FirstLane]] to float
6+
7+
8+
float main(uint i:I) : SV_Target {
9+
const uint uniformIndex = WaveReadLaneFirst ( i ) ;
10+
if ( uniformIndex == i)
11+
{
12+
return sin(uniformIndex);
13+
} else {
14+
return 13;
15+
}
16+
}

0 commit comments

Comments
 (0)