@@ -2105,6 +2105,10 @@ bool AMDGPUOperand::isInlinableImm(MVT type) const {
21052105 // Only plain immediates are inlinable (e.g. "clamp" attribute is not)
21062106 return false ;
21072107 }
2108+
2109+ if (getModifiers ().Lit != LitModifier::None)
2110+ return false ;
2111+
21082112 // TODO: We should avoid using host float here. It would be better to
21092113 // check the float bit values which is what a few other places do.
21102114 // We've had bot failures before due to weird NaN support on mips hosts.
@@ -2349,7 +2353,8 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst &Inst, int64_t Val, bool ApplyMo
23492353 case AMDGPU::OPERAND_REG_INLINE_C_INT64:
23502354 case AMDGPU::OPERAND_REG_INLINE_C_FP64:
23512355 case AMDGPU::OPERAND_REG_INLINE_AC_FP64:
2352- if (AMDGPU::isInlinableLiteral64 (Literal.getZExtValue (),
2356+ if (Lit == LitModifier::None &&
2357+ AMDGPU::isInlinableLiteral64 (Literal.getZExtValue (),
23532358 AsmParser->hasInv2PiInlineImm ())) {
23542359 Inst.addOperand (MCOperand::createImm (Literal.getZExtValue ()));
23552360 return ;
@@ -2386,14 +2391,7 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst &Inst, int64_t Val, bool ApplyMo
23862391 Val = Hi_32 (Val);
23872392 }
23882393 }
2389-
2390- if (Lit != LitModifier::None) {
2391- Inst.addOperand (
2392- MCOperand::createExpr (AMDGPUMCExpr::createLit (Lit, Val, Ctx)));
2393- } else {
2394- Inst.addOperand (MCOperand::createImm (Val));
2395- }
2396- return ;
2394+ break ;
23972395 }
23982396
23992397 // We don't allow fp literals in 64-bit integer instructions. It is
@@ -2405,20 +2403,14 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst &Inst, int64_t Val, bool ApplyMo
24052403 if (CanUse64BitLiterals && Lit == LitModifier::None &&
24062404 (isInt<32 >(Val) || isUInt<32 >(Val)))
24072405 Lit = LitModifier::Lit64;
2408-
2409- if (Lit != LitModifier::None) {
2410- Inst.addOperand (
2411- MCOperand::createExpr (AMDGPUMCExpr::createLit (Lit, Val, Ctx)));
2412- } else {
2413- Inst.addOperand (MCOperand::createImm (Val));
2414- }
2415- return ;
2406+ break ;
24162407
24172408 case AMDGPU::OPERAND_REG_IMM_BF16:
24182409 case AMDGPU::OPERAND_REG_INLINE_C_BF16:
24192410 case AMDGPU::OPERAND_REG_INLINE_C_V2BF16:
24202411 case AMDGPU::OPERAND_REG_IMM_V2BF16:
2421- if (AsmParser->hasInv2PiInlineImm () && Literal == 0x3fc45f306725feed ) {
2412+ if (Lit == LitModifier::None && AsmParser->hasInv2PiInlineImm () &&
2413+ Literal == 0x3fc45f306725feed ) {
24222414 // This is the 1/(2*pi) which is going to be truncated to bf16 with the
24232415 // loss of precision. The constant represents ideomatic fp32 value of
24242416 // 1/(2*pi) = 0.15915494 since bf16 is in fact fp32 with cleared low 16
@@ -2456,14 +2448,19 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst &Inst, int64_t Val, bool ApplyMo
24562448 // We allow precision lost but not overflow or underflow. This should be
24572449 // checked earlier in isLiteralImm()
24582450
2459- uint64_t ImmVal = FPLiteral.bitcastToAPInt ().getZExtValue ();
2460- Inst.addOperand (MCOperand::createImm (ImmVal));
2461- return ;
2451+ Val = FPLiteral.bitcastToAPInt ().getZExtValue ();
2452+ break ;
24622453 }
24632454 default :
24642455 llvm_unreachable (" invalid operand size" );
24652456 }
24662457
2458+ if (Lit != LitModifier::None) {
2459+ Inst.addOperand (
2460+ MCOperand::createExpr (AMDGPUMCExpr::createLit (Lit, Val, Ctx)));
2461+ } else {
2462+ Inst.addOperand (MCOperand::createImm (Val));
2463+ }
24672464 return ;
24682465 }
24692466
@@ -2483,12 +2480,12 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst &Inst, int64_t Val, bool ApplyMo
24832480 case AMDGPU::OPERAND_REG_IMM_V2INT32:
24842481 case AMDGPU::OPERAND_INLINE_SPLIT_BARRIER_INT32:
24852482 case AMDGPU::OPERAND_REG_IMM_NOINLINE_V2FP16:
2486- Inst.addOperand (MCOperand::createImm (Val));
2487- return ;
2483+ break ;
24882484
24892485 case AMDGPU::OPERAND_REG_IMM_INT64:
24902486 case AMDGPU::OPERAND_REG_INLINE_C_INT64:
2491- if (AMDGPU::isInlinableLiteral64 (Val, AsmParser->hasInv2PiInlineImm ())) {
2487+ if (Lit == LitModifier::None &&
2488+ AMDGPU::isInlinableLiteral64 (Val, AsmParser->hasInv2PiInlineImm ())) {
24922489 Inst.addOperand (MCOperand::createImm (Val));
24932490 return ;
24942491 }
@@ -2499,19 +2496,13 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst &Inst, int64_t Val, bool ApplyMo
24992496 // LSBs.
25002497 if (!AsmParser->has64BitLiterals () || Lit == LitModifier::Lit)
25012498 Val = Lo_32 (Val);
2502-
2503- if (Lit != LitModifier::None) {
2504- Inst.addOperand (
2505- MCOperand::createExpr (AMDGPUMCExpr::createLit (Lit, Val, Ctx)));
2506- } else {
2507- Inst.addOperand (MCOperand::createImm (Val));
2508- }
2509- return ;
2499+ break ;
25102500
25112501 case AMDGPU::OPERAND_REG_IMM_FP64:
25122502 case AMDGPU::OPERAND_REG_INLINE_C_FP64:
25132503 case AMDGPU::OPERAND_REG_INLINE_AC_FP64:
2514- if (AMDGPU::isInlinableLiteral64 (Val, AsmParser->hasInv2PiInlineImm ())) {
2504+ if (Lit == LitModifier::None &&
2505+ AMDGPU::isInlinableLiteral64 (Val, AsmParser->hasInv2PiInlineImm ())) {
25152506 Inst.addOperand (MCOperand::createImm (Val));
25162507 return ;
25172508 }
@@ -2534,14 +2525,7 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst &Inst, int64_t Val, bool ApplyMo
25342525 // For FP64 operands lit() specifies the high half of the value.
25352526 if (Lit == LitModifier::Lit)
25362527 Val = Hi_32 (Val);
2537-
2538- if (Lit != LitModifier::None) {
2539- Inst.addOperand (
2540- MCOperand::createExpr (AMDGPUMCExpr::createLit (Lit, Val, Ctx)));
2541- } else {
2542- Inst.addOperand (MCOperand::createImm (Val));
2543- }
2544- return ;
2528+ break ;
25452529
25462530 case AMDGPU::OPERAND_REG_IMM_INT16:
25472531 case AMDGPU::OPERAND_REG_INLINE_C_INT16:
@@ -2554,24 +2538,23 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst &Inst, int64_t Val, bool ApplyMo
25542538 case AMDGPU::OPERAND_REG_INLINE_C_V2BF16:
25552539 case AMDGPU::OPERAND_KIMM32:
25562540 case AMDGPU::OPERAND_KIMM16:
2557- Inst.addOperand (MCOperand::createImm (Val));
2558- return ;
2541+ break ;
25592542
25602543 case AMDGPU::OPERAND_KIMM64:
25612544 if ((isInt<32 >(Val) || isUInt<32 >(Val)) && Lit != LitModifier::Lit64)
25622545 Val <<= 32 ;
2563-
2564- if (Lit != LitModifier::None) {
2565- Inst.addOperand (
2566- MCOperand::createExpr (AMDGPUMCExpr::createLit (Lit, Val, Ctx)));
2567- } else {
2568- Inst.addOperand (MCOperand::createImm (Val));
2569- }
2570- return ;
2546+ break ;
25712547
25722548 default :
25732549 llvm_unreachable (" invalid operand type" );
25742550 }
2551+
2552+ if (Lit != LitModifier::None) {
2553+ Inst.addOperand (
2554+ MCOperand::createExpr (AMDGPUMCExpr::createLit (Lit, Val, Ctx)));
2555+ } else {
2556+ Inst.addOperand (MCOperand::createImm (Val));
2557+ }
25752558}
25762559
25772560void AMDGPUOperand::addRegOperands (MCInst &Inst, unsigned N) const {
0 commit comments