mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
Fix integer undefined behavior due to signed left shift overflow in LLVM.
Reviewed offline by chandlerc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@162623 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -811,14 +811,13 @@ SDValue PPC::get_VSPLTI_elt(SDNode *N, unsigned ByteSize, SelectionDAG &DAG) {
|
||||
}
|
||||
|
||||
// Properly sign extend the value.
|
||||
int ShAmt = (4-ByteSize)*8;
|
||||
int MaskVal = ((int)Value << ShAmt) >> ShAmt;
|
||||
int MaskVal = SignExtend32(Value, ByteSize * 8);
|
||||
|
||||
// If this is zero, don't match, zero matches ISD::isBuildVectorAllZeros.
|
||||
if (MaskVal == 0) return SDValue();
|
||||
|
||||
// Finally, if this value fits in a 5 bit sext field, return it
|
||||
if (((MaskVal << (32-5)) >> (32-5)) == MaskVal)
|
||||
if (SignExtend32<5>(MaskVal) == MaskVal)
|
||||
return DAG.getTargetConstant(MaskVal, MVT::i32);
|
||||
return SDValue();
|
||||
}
|
||||
@@ -2424,7 +2423,7 @@ static SDNode *isBLACompatibleAddress(SDValue Op, SelectionDAG &DAG) {
|
||||
|
||||
int Addr = C->getZExtValue();
|
||||
if ((Addr & 3) != 0 || // Low 2 bits are implicitly zero.
|
||||
(Addr << 6 >> 6) != Addr)
|
||||
SignExtend32<26>(Addr) != Addr)
|
||||
return 0; // Top 6 bits have to be sext of immediate.
|
||||
|
||||
return DAG.getConstant((int)C->getZExtValue() >> 2,
|
||||
@@ -4142,7 +4141,7 @@ SDValue PPCTargetLowering::LowerBUILD_VECTOR(SDValue Op,
|
||||
unsigned TypeShiftAmt = i & (SplatBitSize-1);
|
||||
|
||||
// vsplti + shl self.
|
||||
if (SextVal == (i << (int)TypeShiftAmt)) {
|
||||
if (SextVal == (int)((unsigned)i << TypeShiftAmt)) {
|
||||
SDValue Res = BuildSplatI(i, SplatSize, MVT::Other, DAG, dl);
|
||||
static const unsigned IIDs[] = { // Intrinsic to use for each size.
|
||||
Intrinsic::ppc_altivec_vslb, Intrinsic::ppc_altivec_vslh, 0,
|
||||
@@ -4187,17 +4186,17 @@ SDValue PPCTargetLowering::LowerBUILD_VECTOR(SDValue Op,
|
||||
}
|
||||
|
||||
// t = vsplti c, result = vsldoi t, t, 1
|
||||
if (SextVal == ((i << 8) | (i < 0 ? 0xFF : 0))) {
|
||||
if (SextVal == (int)(((unsigned)i << 8) | (i < 0 ? 0xFF : 0))) {
|
||||
SDValue T = BuildSplatI(i, SplatSize, MVT::v16i8, DAG, dl);
|
||||
return BuildVSLDOI(T, T, 1, Op.getValueType(), DAG, dl);
|
||||
}
|
||||
// t = vsplti c, result = vsldoi t, t, 2
|
||||
if (SextVal == ((i << 16) | (i < 0 ? 0xFFFF : 0))) {
|
||||
if (SextVal == (int)(((unsigned)i << 16) | (i < 0 ? 0xFFFF : 0))) {
|
||||
SDValue T = BuildSplatI(i, SplatSize, MVT::v16i8, DAG, dl);
|
||||
return BuildVSLDOI(T, T, 2, Op.getValueType(), DAG, dl);
|
||||
}
|
||||
// t = vsplti c, result = vsldoi t, t, 3
|
||||
if (SextVal == ((i << 24) | (i < 0 ? 0xFFFFFF : 0))) {
|
||||
if (SextVal == (int)(((unsigned)i << 24) | (i < 0 ? 0xFFFFFF : 0))) {
|
||||
SDValue T = BuildSplatI(i, SplatSize, MVT::v16i8, DAG, dl);
|
||||
return BuildVSLDOI(T, T, 3, Op.getValueType(), DAG, dl);
|
||||
}
|
||||
|
Reference in New Issue
Block a user