@@ -7218,12 +7218,21 @@ SDValue SystemZTargetLowering::combineSTORE(
7218
7218
7219
7219
// Find a replicated immediate and return it if found in Word and its
7220
7220
// type in WordVT.
7221
- auto FindReplicatedImm = [&](ConstantSDNode *C) {
7221
+ auto FindReplicatedImm = [&](ConstantSDNode *C, unsigned TotBytes ) {
7222
7222
// Some constants are better handled with a scalar store.
7223
7223
if (C->getAPIntValue ().getBitWidth () > 64 || C->isAllOnes () ||
7224
7224
isInt<16 >(C->getSExtValue ()) || MemVT.getStoreSize () <= 2 )
7225
7225
return ;
7226
- SystemZVectorConstantInfo VCI (C->getAPIntValue ());
7226
+
7227
+ APInt Val = C->getAPIntValue ();
7228
+ // Truncate Val in case of a truncating store.
7229
+ if (!llvm::isUIntN (TotBytes * 8 , Val.getZExtValue ())) {
7230
+ assert (SN->isTruncatingStore () &&
7231
+ " Non-truncating store and immediate value does not fit?" );
7232
+ Val = Val.trunc (TotBytes * 8 );
7233
+ }
7234
+
7235
+ SystemZVectorConstantInfo VCI (Val);
7227
7236
if (VCI.isVectorConstantLegal (Subtarget) &&
7228
7237
VCI.Opcode == SystemZISD::REPLICATE) {
7229
7238
Word = DAG.getConstant (VCI.OpVals [0 ], SDLoc (SN), MVT::i32 );
@@ -7261,12 +7270,12 @@ SDValue SystemZTargetLowering::combineSTORE(
7261
7270
DAG.isSplatValue (Op1, true /* AllowUndefs*/ )) {
7262
7271
SDValue SplatVal = Op1->getOperand (0 );
7263
7272
if (auto *C = dyn_cast<ConstantSDNode>(SplatVal))
7264
- FindReplicatedImm (C);
7273
+ FindReplicatedImm (C, SplatVal. getValueType (). getStoreSize () );
7265
7274
else
7266
7275
FindReplicatedReg (SplatVal);
7267
7276
} else {
7268
7277
if (auto *C = dyn_cast<ConstantSDNode>(Op1))
7269
- FindReplicatedImm (C);
7278
+ FindReplicatedImm (C, MemVT. getStoreSize () );
7270
7279
else
7271
7280
FindReplicatedReg (Op1);
7272
7281
}
0 commit comments