Skip to content

Commit 18ea6c9

Browse files
authored
AMDGPU: Stop emitting an error on illegal addrspacecasts (llvm#127487)
These cannot be static compile errors, and should be treated as poison. Invalid casts may be introduced which are dynamically dead. For example: ``` void foo(volatile generic int* x) { __builtin_assume(is_shared(x)); *x = 4; } void bar() { private int y; foo(&y); // violation, wrong address space } ``` This could produce a compile time backend error or not depending on the optimization level. Similarly, the new test demonstrates a failure on a lowered atomicrmw which required inserting runtime address space checks. The invalid cases are dynamically dead, we should not error, and the AtomicExpand pass shouldn't have to consider the details of the incoming pointer to produce valid IR. This should go to the release branch. This fixes broken -O0 compiles with 64-bit atomics which would have started failing in 1d03708.
1 parent d25beca commit 18ea6c9

File tree

4 files changed

+687
-17
lines changed

4 files changed

+687
-17
lines changed

llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,11 +2426,8 @@ bool AMDGPULegalizerInfo::legalizeAddrSpaceCast(
24262426
return true;
24272427
}
24282428

2429-
DiagnosticInfoUnsupported InvalidAddrSpaceCast(
2430-
MF.getFunction(), "invalid addrspacecast", B.getDebugLoc());
2431-
2432-
LLVMContext &Ctx = MF.getFunction().getContext();
2433-
Ctx.diagnose(InvalidAddrSpaceCast);
2429+
// Invalid casts are poison.
2430+
// TODO: Should return poison
24342431
B.buildUndef(Dst);
24352432
MI.eraseFromParent();
24362433
return true;

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7341,11 +7341,8 @@ SDValue SITargetLowering::lowerADDRSPACECAST(SDValue Op,
73417341

73427342
// global <-> flat are no-ops and never emitted.
73437343

7344-
const MachineFunction &MF = DAG.getMachineFunction();
7345-
DiagnosticInfoUnsupported InvalidAddrSpaceCast(
7346-
MF.getFunction(), "invalid addrspacecast", SL.getDebugLoc());
7347-
DAG.getContext()->diagnose(InvalidAddrSpaceCast);
7348-
7344+
// Invalid casts are poison.
7345+
// TODO: Should return poison
73497346
return DAG.getUNDEF(Op->getValueType(0));
73507347
}
73517348

0 commit comments

Comments
 (0)