Skip to content

Commit 24c8605

Browse files
authored
AMDGPU/MC: Fix emitting absolute expressions (#136789)
When absolute MCExprs appear in normal instruction operands, we have to emit them like a normal inline constant or literal. More generally, an MCExpr that happens to have an absolute evaluation should be treated exactly like an immediate operand here. No test; I found this downstream, and I don't think it can be triggered upstream yet. Fixes: 1623866 ("[AMDGPU][MC] Support UC_VERSION_* constants. (#95618)")
1 parent 8abc917 commit 24c8605

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -647,13 +647,15 @@ void AMDGPUMCCodeEmitter::getMachineOpValueT16Lo128(
647647
void AMDGPUMCCodeEmitter::getMachineOpValueCommon(
648648
const MCInst &MI, const MCOperand &MO, unsigned OpNo, APInt &Op,
649649
SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI) const {
650+
bool isLikeImm = false;
650651
int64_t Val;
651-
if (MO.isExpr() && MO.getExpr()->evaluateAsAbsolute(Val)) {
652-
Op = Val;
653-
return;
654-
}
655652

656-
if (MO.isExpr() && MO.getExpr()->getKind() != MCExpr::Constant) {
653+
if (MO.isImm()) {
654+
Val = MO.getImm();
655+
isLikeImm = true;
656+
} else if (MO.isExpr() && MO.getExpr()->evaluateAsAbsolute(Val)) {
657+
isLikeImm = true;
658+
} else if (MO.isExpr()) {
657659
// FIXME: If this is expression is PCRel or not should not depend on what
658660
// the expression looks like. Given that this is just a general expression,
659661
// it should probably be FK_Data_4 and whatever is producing
@@ -683,8 +685,12 @@ void AMDGPUMCCodeEmitter::getMachineOpValueCommon(
683685
Op = *Enc;
684686
return;
685687
}
686-
} else if (MO.isImm()) {
687-
Op = MO.getImm();
688+
689+
llvm_unreachable("Operand not supported for SISrc");
690+
}
691+
692+
if (isLikeImm) {
693+
Op = Val;
688694
return;
689695
}
690696

0 commit comments

Comments
 (0)