[llvm] [SDAG] Don't allow implicit trunc in getConstant() (PR #117558)

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 25 05:48:17 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-selectiondag

Author: Nikita Popov (nikic)

<details>
<summary>Changes</summary>

Assert that the passed value is a valid unsigned integer value for the specified type.

For signed values getSignedConstant() / getSignedTargetConstant() should be used instead.

---
Full diff: https://github.com/llvm/llvm-project/pull/117558.diff


1 Files Affected:

- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+1-7) 


``````````diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 3a8ec3c6105bc0..f67f30b8c1ee5f 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -1638,13 +1638,7 @@ SDValue SelectionDAG::getBoolConstant(bool V, const SDLoc &DL, EVT VT,
 SDValue SelectionDAG::getConstant(uint64_t Val, const SDLoc &DL, EVT VT,
                                   bool isT, bool isO) {
   EVT EltVT = VT.getScalarType();
-  assert((EltVT.getSizeInBits() >= 64 ||
-          (uint64_t)((int64_t)Val >> EltVT.getSizeInBits()) + 1 < 2) &&
-         "getConstant with a uint64_t value that doesn't fit in the type!");
-  // TODO: Avoid implicit trunc?
-  // See https://github.com/llvm/llvm-project/issues/112510.
-  return getConstant(APInt(EltVT.getSizeInBits(), Val, /*isSigned=*/false,
-                           /*implicitTrunc=*/true),
+  return getConstant(APInt(EltVT.getSizeInBits(), Val, /*isSigned=*/false),
                      DL, VT, isT, isO);
 }
 

``````````

</details>


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


More information about the llvm-commits mailing list