================
@@ -6557,15 +6560,28 @@ bool SIInstrInfo::isOperandLegal(const MachineInstr 
&MI, unsigned OpIdx,
           (!ST.has64BitLiterals() || InstDesc.getSize() != 4))
         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 64-bit literals are supported and the literal will be 
encoded
-      //        as full 64 bit we still can use it.
-      if (!Is64BitFPOp && (int32_t)Imm < 0 &&
-          (!ST.has64BitLiterals() || AMDGPU::isValid32BitLiteral(Imm, false)))
+      // For signed operands, we can use sign extended 32-bit literals when the
+      // value fits in a signed 32-bit integer. For unsigned operands, we 
reject
+      // negative values (when interpreted as 32-bit) since they would be
+      // zero-extended, not sign-extended.
+      // If 64-bit literals are supported and the literal will be encoded
+      // as full 64 bit we still can use it.
+      if (Is64BitSignedOp) {
+        // Signed operand: 32-bit literal is valid if it fits in int32_t
+        if (!isInt<32>(static_cast<int64_t>(Imm)) &&
+            (!ST.has64BitLiterals() || AMDGPU::isValid32BitLiteral(Imm, 
false)))
----------------
jayfoad wrote:

You should not be calling `isValid32BitLiteral` here. It is less precise than 
the `isInt<32>` check on the line above, since it does not know about 
signedness. We should probably work towards removing `isValid32BitLiteral` or 
teaching it about signedness.

https://github.com/llvm/llvm-project/pull/186575
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to