Skip to content

Commit d58b0f2

Browse files
authored
AMDGPU/MC: Try harder to evaluate absolute MC expressions (#145146)
This is a follow-up to commit 24c8605 ("AMDGPU/MC: Fix emitting absolute expressions (#136789)"). In some downstream work, we end up with an MCTargetExpr that is a maximum (AGVK_Max) in an instruction operand. getMachineOpValueCommon recognizes the absolute nature of the expression and doesn't emit a fixup. getLitEncoding needs to be aligned with this decision, else we end up with a 0 immediate without a corresponding fixup. Note that evaluateAsAbsolute checks for MCConstantExpr as a fast path, so this accepts strictly more cases than before. I've tried several ways to write a test for this without success. The challenge is that there is no upstream way to generate this kind of expression in an instruction operand natively, and trying to create one via inline assembly fails because the assembly parser evaluates the expression to a constant during parsing.
1 parent 54e2f5a commit d58b0f2

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCCodeEmitter.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,9 @@ AMDGPUMCCodeEmitter::getLitEncoding(const MCOperand &MO,
255255
const MCSubtargetInfo &STI) const {
256256
int64_t Imm;
257257
if (MO.isExpr()) {
258-
const auto *C = dyn_cast<MCConstantExpr>(MO.getExpr());
259-
if (!C)
258+
if (!MO.getExpr()->evaluateAsAbsolute(Imm))
260259
return 255;
261-
262-
Imm = C->getValue();
263260
} else {
264-
265261
assert(!MO.isDFPImm());
266262

267263
if (!MO.isImm())

0 commit comments

Comments
 (0)