@@ -88,7 +88,7 @@ class AMDGPUMCCodeEmitter : public MCCodeEmitter {
8888
8989 // / Encode an fp or int literal.
9090 std::optional<uint64_t >
91- getLitEncoding (const MCOperand &MO , const MCOperandInfo &OpInfo ,
91+ getLitEncoding (const MCInstrDesc &Desc , const MCOperand &MO, unsigned OpNo ,
9292 const MCSubtargetInfo &STI,
9393 bool HasMandatoryLiteral = false ) const ;
9494
@@ -219,8 +219,8 @@ static uint32_t getLit16IntEncoding(uint32_t Val, const MCSubtargetInfo &STI) {
219219 return getLit32Encoding (Val, STI);
220220}
221221
222- static uint32_t getLit64Encoding (uint64_t Val, const MCSubtargetInfo &STI ,
223- bool IsFP) {
222+ static uint32_t getLit64Encoding (const MCInstrDesc &Desc, uint64_t Val ,
223+ const MCSubtargetInfo &STI, bool IsFP) {
224224 uint32_t IntImm = getIntInlineImmEncoding (static_cast <int64_t >(Val));
225225 if (IntImm != 0 )
226226 return IntImm;
@@ -255,20 +255,21 @@ static uint32_t getLit64Encoding(uint64_t Val, const MCSubtargetInfo &STI,
255255
256256 // The rest part needs to align with AMDGPUInstPrinter::printLiteral64.
257257
258+ bool CanUse64BitLiterals =
259+ STI.hasFeature (AMDGPU::Feature64BitLiterals) &&
260+ !(Desc.TSFlags & (SIInstrFlags::VOP3 | SIInstrFlags::VOP3P));
258261 if (IsFP) {
259- return STI.hasFeature (AMDGPU::Feature64BitLiterals) && Lo_32 (Val) ? 254
260- : 255 ;
262+ return CanUse64BitLiterals && Lo_32 (Val) ? 254 : 255 ;
261263 }
262264
263- return STI.hasFeature (AMDGPU::Feature64BitLiterals) &&
264- (!isInt<32 >(Val) || !isUInt<32 >(Val))
265- ? 254
266- : 255 ;
265+ return CanUse64BitLiterals && (!isInt<32 >(Val) || !isUInt<32 >(Val)) ? 254
266+ : 255 ;
267267}
268268
269269std::optional<uint64_t > AMDGPUMCCodeEmitter::getLitEncoding (
270- const MCOperand &MO , const MCOperandInfo &OpInfo ,
270+ const MCInstrDesc &Desc , const MCOperand &MO, unsigned OpNo ,
271271 const MCSubtargetInfo &STI, bool HasMandatoryLiteral) const {
272+ const MCOperandInfo &OpInfo = Desc.operands ()[OpNo];
272273 int64_t Imm;
273274 if (MO.isExpr ()) {
274275 if (!MO.getExpr ()->evaluateAsAbsolute (Imm))
@@ -296,14 +297,14 @@ std::optional<uint64_t> AMDGPUMCCodeEmitter::getLitEncoding(
296297
297298 case AMDGPU::OPERAND_REG_IMM_INT64:
298299 case AMDGPU::OPERAND_REG_INLINE_C_INT64:
299- return getLit64Encoding (static_cast <uint64_t >(Imm), STI, false );
300+ return getLit64Encoding (Desc, static_cast <uint64_t >(Imm), STI, false );
300301
301302 case AMDGPU::OPERAND_REG_INLINE_C_FP64:
302303 case AMDGPU::OPERAND_REG_INLINE_AC_FP64:
303- return getLit64Encoding (static_cast <uint64_t >(Imm), STI, true );
304+ return getLit64Encoding (Desc, static_cast <uint64_t >(Imm), STI, true );
304305
305306 case AMDGPU::OPERAND_REG_IMM_FP64: {
306- auto Enc = getLit64Encoding (static_cast <uint64_t >(Imm), STI, true );
307+ auto Enc = getLit64Encoding (Desc, static_cast <uint64_t >(Imm), STI, true );
307308 return (HasMandatoryLiteral && Enc == 255 ) ? 254 : Enc;
308309 }
309310
@@ -444,7 +445,7 @@ void AMDGPUMCCodeEmitter::encodeInstruction(const MCInst &MI,
444445
445446 // Is this operand a literal immediate?
446447 const MCOperand &Op = MI.getOperand (i);
447- auto Enc = getLitEncoding (Op, Desc. operands ()[i] , STI);
448+ auto Enc = getLitEncoding (Desc, Op, i , STI);
448449 if (!Enc || (*Enc != 255 && *Enc != 254 ))
449450 continue ;
450451
@@ -518,7 +519,7 @@ void AMDGPUMCCodeEmitter::getSDWASrcEncoding(const MCInst &MI, unsigned OpNo,
518519 return ;
519520 } else {
520521 const MCInstrDesc &Desc = MCII.get (MI.getOpcode ());
521- auto Enc = getLitEncoding (MO, Desc. operands ()[ OpNo] , STI);
522+ auto Enc = getLitEncoding (Desc, MO, OpNo, STI);
522523 if (Enc && *Enc != 255 ) {
523524 Op = *Enc | SDWA9EncValues::SRC_SGPR_MASK;
524525 return ;
@@ -701,8 +702,7 @@ void AMDGPUMCCodeEmitter::getMachineOpValueCommon(
701702 if (AMDGPU::isSISrcOperand (Desc, OpNo)) {
702703 bool HasMandatoryLiteral =
703704 AMDGPU::hasNamedOperand (MI.getOpcode (), AMDGPU::OpName::imm);
704- if (auto Enc = getLitEncoding (MO, Desc.operands ()[OpNo], STI,
705- HasMandatoryLiteral)) {
705+ if (auto Enc = getLitEncoding (Desc, MO, OpNo, STI, HasMandatoryLiteral)) {
706706 Op = *Enc;
707707 return ;
708708 }
0 commit comments