Skip to content

Commit f4805ac

Browse files
committed
Reworked and fixed.
1 parent 3c1fea6 commit f4805ac

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7218,12 +7218,21 @@ SDValue SystemZTargetLowering::combineSTORE(
72187218

72197219
// Find a replicated immediate and return it if found in Word and its
72207220
// type in WordVT.
7221-
auto FindReplicatedImm = [&](ConstantSDNode *C) {
7221+
auto FindReplicatedImm = [&](ConstantSDNode *C, unsigned TotBytes) {
72227222
// Some constants are better handled with a scalar store.
72237223
if (C->getAPIntValue().getBitWidth() > 64 || C->isAllOnes() ||
72247224
isInt<16>(C->getSExtValue()) || MemVT.getStoreSize() <= 2)
72257225
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);
72277236
if (VCI.isVectorConstantLegal(Subtarget) &&
72287237
VCI.Opcode == SystemZISD::REPLICATE) {
72297238
Word = DAG.getConstant(VCI.OpVals[0], SDLoc(SN), MVT::i32);
@@ -7261,12 +7270,12 @@ SDValue SystemZTargetLowering::combineSTORE(
72617270
DAG.isSplatValue(Op1, true/*AllowUndefs*/)) {
72627271
SDValue SplatVal = Op1->getOperand(0);
72637272
if (auto *C = dyn_cast<ConstantSDNode>(SplatVal))
7264-
FindReplicatedImm(C);
7273+
FindReplicatedImm(C, SplatVal.getValueType().getStoreSize());
72657274
else
72667275
FindReplicatedReg(SplatVal);
72677276
} else {
72687277
if (auto *C = dyn_cast<ConstantSDNode>(Op1))
7269-
FindReplicatedImm(C);
7278+
FindReplicatedImm(C, MemVT.getStoreSize());
72707279
else
72717280
FindReplicatedReg(Op1);
72727281
}

llvm/test/CodeGen/SystemZ/dag-combine-07.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ define void @func_5(ptr %Dst) {
1616
; CHECK-NEXT: stg %r0, 0(%r1)
1717
; CHECK-NEXT: lgrl %r1, G1@GOT
1818
; CHECK-NEXT: stg %r0, 0(%r1)
19-
; CHECK-NEXT: st %r0, 0(%r2)
19+
; CHECK-NEXT: mvhi 0(%r2), 2
2020
; CHECK-NEXT: br %r14
2121
store i64 214748364802, ptr @G2, align 8
2222
store i64 214748364802, ptr @G1, align 8

0 commit comments

Comments
 (0)