Skip to content

Commit 2f4275b

Browse files
authored
AMDGPU: skip AMDGPUAttributor and AMDGPUImageIntrinsicOptimizerPass on R600. (#162207)
These passes call `getSubtarget<GCNSubtarget>`, which doesn't work on R600 targets, as that uses an `R600Subtarget` type, instead. Unfortunately, `TargetMachine::getSubtarget<ST>` does an unchecked static_cast to `ST&`, which makes it easy for this error to go undetected. The modifications here were verified by running check-llvm with an assert added to getSubtarget. However, that asssert requires that RTTI is enabled, which LLVM doesn't use, so I've reverted the assert before sending this fix upstream. These errors have been present for some time, but were detected after #162040 caused an uninitialized memory read to be reported by asan/msan.
1 parent 6267e71 commit 2f4275b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,10 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
929929
ThinOrFullLTOPhase Phase) {
930930
if (Level != OptimizationLevel::O0) {
931931
if (!isLTOPreLink(Phase)) {
932-
AMDGPUAttributorOptions Opts;
933-
MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
932+
if (getTargetTriple().isAMDGCN()) {
933+
AMDGPUAttributorOptions Opts;
934+
MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
935+
}
934936
}
935937
}
936938
});
@@ -1296,7 +1298,8 @@ void AMDGPUPassConfig::addIRPasses() {
12961298
if (LowerCtorDtor)
12971299
addPass(createAMDGPUCtorDtorLoweringLegacyPass());
12981300

1299-
if (isPassEnabled(EnableImageIntrinsicOptimizer))
1301+
if (TM.getTargetTriple().isAMDGCN() &&
1302+
isPassEnabled(EnableImageIntrinsicOptimizer))
13001303
addPass(createAMDGPUImageIntrinsicOptimizerPass(&TM));
13011304

13021305
// This can be disabled by passing ::Disable here or on the command line

0 commit comments

Comments
 (0)