Skip to content

Commit bfd4575

Browse files
committed
Revert "[AMDGPU] SelectionDAG divergence tracking should take into account Target divergency. (#144947)"
This reverts commit 8ac7210. This breaks the building the AArch64 backend, e.g. see #144947 Revert to unbreak the build. Also reverts follow-up commits 1e76f01.
1 parent 378f248 commit bfd4575

File tree

8 files changed

+26
-96
lines changed

8 files changed

+26
-96
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ class SelectionDAG {
238238
LLVMContext *Context;
239239
CodeGenOptLevel OptLevel;
240240

241-
bool DivergentTarget = false;
242-
243241
UniformityInfo *UA = nullptr;
244242
FunctionLoweringInfo * FLI = nullptr;
245243

@@ -473,16 +471,14 @@ class SelectionDAG {
473471
Pass *PassPtr, const TargetLibraryInfo *LibraryInfo,
474472
UniformityInfo *UA, ProfileSummaryInfo *PSIin,
475473
BlockFrequencyInfo *BFIin, MachineModuleInfo &MMI,
476-
FunctionVarLocs const *FnVarLocs, bool HasDivergency);
474+
FunctionVarLocs const *FnVarLocs);
477475

478476
void init(MachineFunction &NewMF, OptimizationRemarkEmitter &NewORE,
479477
MachineFunctionAnalysisManager &AM,
480478
const TargetLibraryInfo *LibraryInfo, UniformityInfo *UA,
481479
ProfileSummaryInfo *PSIin, BlockFrequencyInfo *BFIin,
482-
MachineModuleInfo &MMI, FunctionVarLocs const *FnVarLocs,
483-
bool HasDivergency) {
484-
init(NewMF, NewORE, nullptr, LibraryInfo, UA, PSIin, BFIin, MMI, FnVarLocs,
485-
HasDivergency);
480+
MachineModuleInfo &MMI, FunctionVarLocs const *FnVarLocs) {
481+
init(NewMF, NewORE, nullptr, LibraryInfo, UA, PSIin, BFIin, MMI, FnVarLocs);
486482
MFAM = &AM;
487483
}
488484

llvm/include/llvm/CodeGen/SelectionDAGISel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ class SelectionDAGISel {
5757
AssumptionCache *AC = nullptr;
5858
GCFunctionInfo *GFI = nullptr;
5959
SSPLayoutInfo *SP = nullptr;
60+
#if !defined(NDEBUG) && LLVM_ENABLE_ABI_BREAKING_CHECKS
6061
TargetTransformInfo *TTI = nullptr;
62+
#endif
6163
CodeGenOptLevel OptLevel;
6264
const TargetInstrInfo *TII;
6365
const TargetLowering *TLI;

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ void SelectionDAG::init(MachineFunction &NewMF,
13701370
const TargetLibraryInfo *LibraryInfo,
13711371
UniformityInfo *NewUA, ProfileSummaryInfo *PSIin,
13721372
BlockFrequencyInfo *BFIin, MachineModuleInfo &MMIin,
1373-
FunctionVarLocs const *VarLocs, bool HasDivergency) {
1373+
FunctionVarLocs const *VarLocs) {
13741374
MF = &NewMF;
13751375
SDAGISelPass = PassPtr;
13761376
ORE = &NewORE;
@@ -1383,7 +1383,6 @@ void SelectionDAG::init(MachineFunction &NewMF,
13831383
BFI = BFIin;
13841384
MMI = &MMIin;
13851385
FnVarLocs = VarLocs;
1386-
DivergentTarget = HasDivergency;
13871386
}
13881387

13891388
SelectionDAG::~SelectionDAG() {
@@ -2330,8 +2329,7 @@ SDValue SelectionDAG::getRegister(Register Reg, EVT VT) {
23302329
return SDValue(E, 0);
23312330

23322331
auto *N = newSDNode<RegisterSDNode>(Reg, VTs);
2333-
N->SDNodeBits.IsDivergent =
2334-
DivergentTarget && TLI->isSDNodeSourceOfDivergence(N, FLI, UA);
2332+
N->SDNodeBits.IsDivergent = TLI->isSDNodeSourceOfDivergence(N, FLI, UA);
23352333
CSEMap.InsertNode(N, IP);
23362334
InsertNode(N);
23372335
return SDValue(N, 0);
@@ -12069,8 +12067,6 @@ static bool gluePropagatesDivergence(const SDNode *Node) {
1206912067
}
1207012068

1207112069
bool SelectionDAG::calculateDivergence(SDNode *N) {
12072-
if(!DivergentTarget)
12073-
return false;
1207412070
if (TLI->isSDNodeAlwaysUniform(N)) {
1207512071
assert(!TLI->isSDNodeSourceOfDivergence(N, FLI, UA) &&
1207612072
"Conflicting divergence information!");
@@ -12090,8 +12086,6 @@ bool SelectionDAG::calculateDivergence(SDNode *N) {
1209012086
}
1209112087

1209212088
void SelectionDAG::updateDivergence(SDNode *N) {
12093-
if (!DivergentTarget)
12094-
return;
1209512089
SmallVector<SDNode *, 16> Worklist(1, N);
1209612090
do {
1209712091
N = Worklist.pop_back_val();
@@ -13639,20 +13633,16 @@ void SelectionDAG::createOperands(SDNode *Node, ArrayRef<SDValue> Vals) {
1363913633
Ops[I].setInitial(Vals[I]);
1364013634
EVT VT = Ops[I].getValueType();
1364113635

13642-
// Take care of the Node's operands iff target has divergence
1364313636
// Skip Chain. It does not carry divergence.
13644-
if (DivergentTarget && VT != MVT::Other &&
13637+
if (VT != MVT::Other &&
1364513638
(VT != MVT::Glue || gluePropagatesDivergence(Ops[I].getNode())) &&
1364613639
Ops[I].getNode()->isDivergent()) {
13647-
// Node is going to be divergent if at least one of its operand is
13648-
// divergent, unless it belongs to the "AlwaysUniform" exemptions.
1364913640
IsDivergent = true;
1365013641
}
1365113642
}
1365213643
Node->NumOperands = Vals.size();
1365313644
Node->OperandList = Ops;
13654-
// Check the divergence of the Node itself.
13655-
if (DivergentTarget && !TLI->isSDNodeAlwaysUniform(Node)) {
13645+
if (!TLI->isSDNodeAlwaysUniform(Node)) {
1365613646
IsDivergent |= TLI->isSDNodeSourceOfDivergence(Node, FLI, UA);
1365713647
Node->SDNodeBits.IsDivergent = IsDivergent;
1365813648
}

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,7 @@ void SelectionDAGISel::initializeAnalysisResults(
482482
MachineModuleInfo &MMI =
483483
MAMP.getCachedResult<MachineModuleAnalysis>(*Fn.getParent())->getMMI();
484484

485-
TTI = &FAM.getResult<TargetIRAnalysis>(Fn);
486-
487-
CurDAG->init(*MF, *ORE, MFAM, LibInfo, UA, PSI, BFI, MMI, FnVarLocs,
488-
TTI->hasBranchDivergence(&Fn));
485+
CurDAG->init(*MF, *ORE, MFAM, LibInfo, UA, PSI, BFI, MMI, FnVarLocs);
489486

490487
// Now get the optional analyzes if we want to.
491488
// This is based on the possibly changed OptLevel (after optnone is taken
@@ -503,6 +500,10 @@ void SelectionDAGISel::initializeAnalysisResults(
503500
BatchAA = std::nullopt;
504501

505502
SP = &FAM.getResult<SSPLayoutAnalysis>(Fn);
503+
504+
#if !defined(NDEBUG) && LLVM_ENABLE_ABI_BREAKING_CHECKS
505+
TTI = &FAM.getResult<TargetIRAnalysis>(Fn);
506+
#endif
506507
}
507508

508509
void SelectionDAGISel::initializeAnalysisResults(MachineFunctionPass &MFP) {
@@ -538,10 +539,7 @@ void SelectionDAGISel::initializeAnalysisResults(MachineFunctionPass &MFP) {
538539
MachineModuleInfo &MMI =
539540
MFP.getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
540541

541-
TTI = &MFP.getAnalysis<TargetTransformInfoWrapperPass>().getTTI(Fn);
542-
543-
CurDAG->init(*MF, *ORE, &MFP, LibInfo, UA, PSI, BFI, MMI, FnVarLocs,
544-
TTI->hasBranchDivergence(&Fn));
542+
CurDAG->init(*MF, *ORE, &MFP, LibInfo, UA, PSI, BFI, MMI, FnVarLocs);
545543

546544
// Now get the optional analyzes if we want to.
547545
// This is based on the possibly changed OptLevel (after optnone is taken
@@ -560,6 +558,10 @@ void SelectionDAGISel::initializeAnalysisResults(MachineFunctionPass &MFP) {
560558
BatchAA = std::nullopt;
561559

562560
SP = &MFP.getAnalysis<StackProtector>().getLayoutInfo();
561+
562+
#if !defined(NDEBUG) && LLVM_ENABLE_ABI_BREAKING_CHECKS
563+
TTI = &MFP.getAnalysis<TargetTransformInfoWrapperPass>().getTTI(Fn);
564+
#endif
563565
}
564566

565567
bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {

llvm/test/CodeGen/AMDGPU/load-constant-always-uniform.ll

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ define amdgpu_cs void @test_uniform_load_b96(ptr addrspace(1) %ptr, i32 %arg) "a
1818
; GFX11-NEXT: s_load_b64 s[2:3], s[0:1], 0x0
1919
; GFX11-NEXT: s_load_b32 s0, s[0:1], 0x8
2020
; GFX11-NEXT: s_waitcnt lgkmcnt(0)
21-
; GFX11-NEXT: s_or_b32 s1, s2, s3
22-
; GFX11-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
23-
; GFX11-NEXT: s_or_b32 s0, s0, s1
24-
; GFX11-NEXT: v_mov_b32_e32 v2, s0
21+
; GFX11-NEXT: v_mov_b32_e32 v2, s3
22+
; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1)
23+
; GFX11-NEXT: v_or3_b32 v2, s2, v2, s0
2524
; GFX11-NEXT: global_store_b32 v[0:1], v2, off
2625
; GFX11-NEXT: s_endpgm
2726
;
@@ -34,14 +33,12 @@ define amdgpu_cs void @test_uniform_load_b96(ptr addrspace(1) %ptr, i32 %arg) "a
3433
; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
3534
; GFX12-NEXT: v_add_co_ci_u32_e64 v3, null, v1, v3, vcc_lo
3635
; GFX12-NEXT: v_readfirstlane_b32 s0, v2
37-
; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(SALU_CYCLE_1)
36+
; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_1)
3837
; GFX12-NEXT: v_readfirstlane_b32 s1, v3
3938
; GFX12-NEXT: s_load_b96 s[0:2], s[0:1], 0x0
4039
; GFX12-NEXT: s_wait_kmcnt 0x0
41-
; GFX12-NEXT: s_or_b32 s0, s0, s1
42-
; GFX12-NEXT: s_or_b32 s0, s2, s0
43-
; GFX12-NEXT: s_delay_alu instid0(SALU_CYCLE_1)
4440
; GFX12-NEXT: v_mov_b32_e32 v2, s0
41+
; GFX12-NEXT: v_or3_b32 v2, v2, s1, s2
4542
; GFX12-NEXT: global_store_b32 v[0:1], v2, off
4643
; GFX12-NEXT: s_endpgm
4744
bb:

llvm/test/CodeGen/AMDGPU/test_isel_single_lane.ll

Lines changed: 0 additions & 47 deletions
This file was deleted.

llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "llvm/CodeGen/SelectionDAGAddressAnalysis.h"
1010
#include "llvm/Analysis/MemoryLocation.h"
1111
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
12-
#include "llvm/Analysis/TargetTransformInfo.h"
1312
#include "llvm/AsmParser/Parser.h"
1413
#include "llvm/CodeGen/MachineModuleInfo.h"
1514
#include "llvm/CodeGen/SelectionDAG.h"
@@ -79,12 +78,8 @@ class SelectionDAGAddressAnalysisTest : public testing::Test {
7978
if (!DAG)
8079
report_fatal_error("DAG?");
8180
OptimizationRemarkEmitter ORE(F);
82-
FunctionAnalysisManager FAM;
83-
FAM.registerPass([&] { return TM->getTargetIRAnalysis(); });
84-
85-
TargetTransformInfo &TTI = FAM.getResult<TargetIRAnalysis>(*F);
8681
DAG->init(*MF, ORE, nullptr, nullptr, nullptr, nullptr, nullptr, MMI,
87-
nullptr, TTI.hasBranchDivergence());
82+
nullptr);
8883
}
8984

9085
TargetLoweringBase::LegalizeTypeAction getTypeAction(EVT VT) {

llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
10-
#include "llvm/Analysis/TargetTransformInfo.h"
1110
#include "llvm/AsmParser/Parser.h"
1211
#include "llvm/CodeGen/MachineModuleInfo.h"
1312
#include "llvm/CodeGen/SDPatternMatch.h"
@@ -77,12 +76,8 @@ class SelectionDAGPatternMatchTest : public testing::Test {
7776
if (!DAG)
7877
report_fatal_error("DAG?");
7978
OptimizationRemarkEmitter ORE(F);
80-
FunctionAnalysisManager FAM;
81-
FAM.registerPass([&] { return TM->getTargetIRAnalysis(); });
82-
83-
TargetTransformInfo &TTI = FAM.getResult<TargetIRAnalysis>(*F);
8479
DAG->init(*MF, ORE, nullptr, nullptr, nullptr, nullptr, nullptr, MMI,
85-
nullptr, TTI.hasBranchDivergence());
80+
nullptr);
8681
}
8782

8883
TargetLoweringBase::LegalizeTypeAction getTypeAction(EVT VT) {

0 commit comments

Comments
 (0)