Skip to content

Commit 8895932

Browse files
committed
[NVPTX] Avoid implicit truncation in getConstant()
Either use getSignedConstant() or change variable type to unsigned to avoid unnecessary sign extension in the first place.
1 parent 8b49091 commit 8895932

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3936,8 +3936,8 @@ bool NVPTXDAGToDAGISel::SelectADDRri_imp(
39363936
if (!CN->getAPIntValue().isSignedIntN(32))
39373937
return false;
39383938

3939-
Offset = CurDAG->getTargetConstant(CN->getSExtValue(), SDLoc(OpNode),
3940-
MVT::i32);
3939+
Offset = CurDAG->getSignedTargetConstant(CN->getSExtValue(),
3940+
SDLoc(OpNode), MVT::i32);
39413941
return true;
39423942
}
39433943
}

llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,10 +2714,10 @@ SDValue NVPTXTargetLowering::LowerFROUND32(SDValue Op,
27142714

27152715
// RoundedA = (float) (int) ( A > 0 ? (A + 0.5f) : (A - 0.5f))
27162716
SDValue Bitcast = DAG.getNode(ISD::BITCAST, SL, MVT::i32, A);
2717-
const int SignBitMask = 0x80000000;
2717+
const unsigned SignBitMask = 0x80000000;
27182718
SDValue Sign = DAG.getNode(ISD::AND, SL, MVT::i32, Bitcast,
27192719
DAG.getConstant(SignBitMask, SL, MVT::i32));
2720-
const int PointFiveInBits = 0x3F000000;
2720+
const unsigned PointFiveInBits = 0x3F000000;
27212721
SDValue PointFiveWithSignRaw =
27222722
DAG.getNode(ISD::OR, SL, MVT::i32, Sign,
27232723
DAG.getConstant(PointFiveInBits, SL, MVT::i32));
@@ -3031,9 +3031,9 @@ SDValue NVPTXTargetLowering::LowerVAARG(SDValue Op, SelectionDAG &DAG) const {
30313031
ISD::ADD, DL, VAList.getValueType(), VAList,
30323032
DAG.getConstant(MA->value() - 1, DL, VAList.getValueType()));
30333033

3034-
VAList = DAG.getNode(
3035-
ISD::AND, DL, VAList.getValueType(), VAList,
3036-
DAG.getConstant(-(int64_t)MA->value(), DL, VAList.getValueType()));
3034+
VAList = DAG.getNode(ISD::AND, DL, VAList.getValueType(), VAList,
3035+
DAG.getSignedConstant(-(int64_t)MA->value(), DL,
3036+
VAList.getValueType()));
30373037
}
30383038

30393039
// Increment the pointer, VAList, to the next vaarg

0 commit comments

Comments
 (0)