[llvm] [AMDGPU] Prevent folding of the negative i32 literals as i64 (PR #70274)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 26 02:50:31 PDT 2023
================
@@ -5500,6 +5500,15 @@ bool SIInstrInfo::isOperandLegal(const MachineInstr &MI, unsigned OpIdx,
if (Is64BitOp && !AMDGPU::isValid32BitLiteral(Imm, Is64BitFPOp) &&
!AMDGPU::isInlinableLiteral64(Imm, ST.hasInv2PiInlineImm()))
return false;
+
+ // FIXME: We can use sign extended 64-bit literals, but only for signed
+ // operands. At the moment we do not know if an operand is signed.
+ // Such operand will be encoded as its low 32 bits and then either
+ // correctly sign extended or incorrectly zero extended by HW.
+ if (Is64BitOp && !Is64BitFPOp && isInt<32>(Imm) &&
+ (int32_t)Lo_32(Imm) < 0 &&
+ !AMDGPU::isInlinableLiteral64(Imm, ST.hasInv2PiInlineImm()))
+ return false;
}
----------------
jayfoad wrote:
Could refactor this whole block as:
```
if (Is64BitOp && !AMDGPU::isInlinableLiteral64(Imm, ST.hasInv2PiInlineImm())) {
if (!AMDGPU::isValid32BitLiteral(Imm, Is64BitFPOp))
return false;
... new code here ...
}
```
https://github.com/llvm/llvm-project/pull/70274
More information about the llvm-commits
mailing list