Skip to content

Commit eab4adb

Browse files
committed
Fix bitwidth problem in FindReplicatedImm().
1 parent 7c63b10 commit eab4adb

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7218,12 +7218,12 @@ 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, unsigned TotBytes) {
7221+
auto FindReplicatedImm = [&](ConstantSDNode *C) {
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(APInt(TotBytes * 8, C->getZExtValue()));
7226+
SystemZVectorConstantInfo VCI(C->getAPIntValue());
72277227
if (VCI.isVectorConstantLegal(Subtarget) &&
72287228
VCI.Opcode == SystemZISD::REPLICATE) {
72297229
Word = DAG.getConstant(VCI.OpVals[0], SDLoc(SN), MVT::i32);
@@ -7261,12 +7261,12 @@ SDValue SystemZTargetLowering::combineSTORE(
72617261
DAG.isSplatValue(Op1, true/*AllowUndefs*/)) {
72627262
SDValue SplatVal = Op1->getOperand(0);
72637263
if (auto *C = dyn_cast<ConstantSDNode>(SplatVal))
7264-
FindReplicatedImm(C, SplatVal.getValueType().getStoreSize());
7264+
FindReplicatedImm(C);
72657265
else
72667266
FindReplicatedReg(SplatVal);
72677267
} else {
72687268
if (auto *C = dyn_cast<ConstantSDNode>(Op1))
7269-
FindReplicatedImm(C, MemVT.getStoreSize());
7269+
FindReplicatedImm(C);
72707270
else
72717271
FindReplicatedReg(Op1);
72727272
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z16 | FileCheck %s
3+
;
4+
; Test that SystemZTargetLowering::combineSTORE() does not crash on a
5+
; truncated immediate.
6+
7+
@G1 = external global i64, align 8
8+
@G2 = external global i64, align 8
9+
10+
define void @func_5(ptr %Dst) {
11+
; CHECK-LABEL: func_5:
12+
; CHECK: # %bb.0:
13+
; CHECK-NEXT: lgrl %r1, G2@GOT
14+
; CHECK-NEXT: llihl %r0, 50
15+
; CHECK-NEXT: oill %r0, 2
16+
; CHECK-NEXT: stg %r0, 0(%r1)
17+
; CHECK-NEXT: lgrl %r1, G1@GOT
18+
; CHECK-NEXT: stg %r0, 0(%r1)
19+
; CHECK-NEXT: st %r0, 0(%r2)
20+
; CHECK-NEXT: br %r14
21+
store i64 214748364802, ptr @G2, align 8
22+
store i64 214748364802, ptr @G1, align 8
23+
%1 = load i32, ptr getelementptr inbounds (i8, ptr @G1, i64 4), align 4
24+
store i32 %1, ptr %Dst, align 4
25+
ret void
26+
}

0 commit comments

Comments
 (0)