[llvm] [NVPTX] enforce signed 32 bit type for immediate offset (PR #99682)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 19 12:58:41 PDT 2024


================
@@ -3914,8 +3914,13 @@ bool NVPTXDAGToDAGISel::SelectADDRri_imp(
         Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), mvt);
       else
         Base = Addr.getOperand(0);
-      Offset = CurDAG->getTargetConstant(CN->getZExtValue(), SDLoc(OpNode),
-                                         mvt);
+
+      // Offset is a signed i32 constant in PTX [register+offset] address mode
----------------
Artem-B wrote:

Nit: Offset must fit in a 32-bit signed int.

Functionally, the code is fine, but I wonder if using `getSignificantBits() <= 32` instead would reflect your intent a bit better. I find the **is** part of `isSignedIntN(32)` to be somewhat misleading in this context. Naming it `fitsSignedIntN(32)` would be better, IMO. Maybe it's just me. 

https://github.com/llvm/llvm-project/pull/99682


More information about the llvm-commits mailing list