aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2024-08-16 09:21:11 -0700
committerGitHub <noreply@github.com>2024-08-16 09:21:11 -0700
commit7afb51e035709e7f2532452054a39fe968444504 (patch)
treef4884eac4c235c7d1643f443aa3d9d575339546b /llvm/lib/CodeGen
parent1164e4aef2844ac3d35153ffe6376db9abda704a (diff)
downloadllvm-7afb51e035709e7f2532452054a39fe968444504.zip
llvm-7afb51e035709e7f2532452054a39fe968444504.tar.gz
llvm-7afb51e035709e7f2532452054a39fe968444504.tar.bz2
[SelectionDAG][X86] Add SelectionDAG::getSignedConstant and use it in a few places. (#104555)
PR #80309 proposes to have users of APInt's uint64_t constructor opt-in to implicit truncation. Currently, that patch requires SelectionDAG::getConstant to opt-in. This patch adds getSignedConstant so we can start fixing some of the cases that require implicit truncation.
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp2
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp9
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp2
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp4
4 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index e7f7653..debecc4 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -2601,7 +2601,7 @@ SDValue SelectionDAGLegalize::expandFrexp(SDNode *Node) const {
SDValue IsDenormal =
DAG.getSetCC(dl, SetCCVT, Abs, SmallestNormalizedInt, ISD::SETULT);
- SDValue MinExp = DAG.getConstant(MinExpVal, dl, ExpVT);
+ SDValue MinExp = DAG.getSignedConstant(MinExpVal, dl, ExpVT);
SDValue Zero = DAG.getConstant(0, dl, ExpVT);
SDValue ScaledAsInt = DAG.getNode(ISD::BITCAST, dl, AsIntVT, ScaleUp);
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 7bf90ce..2401bb5 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -1747,6 +1747,15 @@ SDValue SelectionDAG::getConstant(const ConstantInt &Val, const SDLoc &DL,
return Result;
}
+SDValue SelectionDAG::getSignedConstant(int64_t Val, const SDLoc &DL, EVT VT,
+ bool isT, bool isO) {
+ unsigned Size = VT.getScalarSizeInBits();
+ assert(
+ isIntN(Size, Val) &&
+ "getSignedConstant with a int64_t value that doesn't fit in the type!");
+ return getConstant(APInt(Size, Val, true), DL, VT, isT, isO);
+}
+
SDValue SelectionDAG::getAllOnesConstant(const SDLoc &DL, EVT VT, bool IsTarget,
bool IsOpaque) {
return getConstant(APInt::getAllOnes(VT.getScalarSizeInBits()), DL, VT,
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 7cdd3d4..8e24f5bd 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -4474,7 +4474,7 @@ void SelectionDAGBuilder::visitAlloca(const AllocaInst &I) {
// Mask out the low bits for alignment purposes.
AllocSize = DAG.getNode(ISD::AND, dl, AllocSize.getValueType(), AllocSize,
- DAG.getConstant(~StackAlignMask, dl, IntPtr));
+ DAG.getSignedConstant(~StackAlignMask, dl, IntPtr));
SDValue Ops[] = {
getRoot(), AllocSize,
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index c1a87de..3c499ca 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -6349,9 +6349,9 @@ SDValue TargetLowering::BuildSDIV(SDNode *N, SelectionDAG &DAG,
}
MagicFactors.push_back(DAG.getConstant(magics.Magic, dl, SVT));
- Factors.push_back(DAG.getConstant(NumeratorFactor, dl, SVT));
+ Factors.push_back(DAG.getSignedConstant(NumeratorFactor, dl, SVT));
Shifts.push_back(DAG.getConstant(magics.ShiftAmount, dl, ShSVT));
- ShiftMasks.push_back(DAG.getConstant(ShiftMask, dl, SVT));
+ ShiftMasks.push_back(DAG.getSignedConstant(ShiftMask, dl, SVT));
return true;
};