[llvm] [SDAG] Don't allow implicit trunc in getConstant() (PR #117558)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 25 05:47:39 PST 2024
https://github.com/nikic created https://github.com/llvm/llvm-project/pull/117558
Assert that the passed value is a valid unsigned integer value for the specified type.
For signed values getSignedConstant() / getSignedTargetConstant() should be used instead.
>From 45be4ce0286b70208918631b84040560443a9974 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Fri, 15 Nov 2024 16:55:59 +0100
Subject: [PATCH] [SDAG] Don't allow implicit trunc in getConstant()
Assert that the passed value is a valid unsigned integer value
for the specified type.
For signed values getSignedConstant() / getSignedTargetConstant()
should be used instead.
---
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
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);
}
More information about the llvm-commits
mailing list