Skip to content

Commit 9af4b71

Browse files
committed
[RISCV][SelectionDAG] Sign extend splats of i32 in getConstant on RV64
We get better constant materialization if we sign extend the value to be splatted for i32 on RV64 instead of zero extending it.
1 parent 56f7c7e commit 9af4b71

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,11 @@ SDValue SelectionDAG::getConstant(const ConstantInt &Val, const SDLoc &DL,
16201620
if (VT.isVector() && TLI->getTypeAction(*getContext(), EltVT) ==
16211621
TargetLowering::TypePromoteInteger) {
16221622
EltVT = TLI->getTypeToTransformTo(*getContext(), EltVT);
1623-
APInt NewVal = Elt->getValue().zextOrTrunc(EltVT.getSizeInBits());
1623+
APInt NewVal;
1624+
if (TLI->isSExtCheaperThanZExt(VT.getScalarType(), EltVT))
1625+
NewVal = Elt->getValue().sextOrTrunc(EltVT.getSizeInBits());
1626+
else
1627+
NewVal = Elt->getValue().zextOrTrunc(EltVT.getSizeInBits());
16241628
Elt = ConstantInt::get(*getContext(), NewVal);
16251629
}
16261630
// In other cases the element type is illegal and needs to be expanded, for

0 commit comments

Comments
 (0)