[SystemZ] Fix bitwidth problem in FindReplicatedImm(). (#115383)
A test case emerged with an i32 truncating store of an i64 constant operand, where the i64 constant did not fit in 32 bits, which caused FindReplicatedImm() to crash. Make sure to truncate the APInt in these cases.
This commit is contained in:
@@ -7223,7 +7223,16 @@ SDValue SystemZTargetLowering::combineSTORE(
|
||||
if (C->getAPIntValue().getBitWidth() > 64 || C->isAllOnes() ||
|
||||
isInt<16>(C->getSExtValue()) || MemVT.getStoreSize() <= 2)
|
||||
return;
|
||||
SystemZVectorConstantInfo VCI(APInt(TotBytes * 8, C->getZExtValue()));
|
||||
|
||||
APInt Val = C->getAPIntValue();
|
||||
// Truncate Val in case of a truncating store.
|
||||
if (!llvm::isUIntN(TotBytes * 8, Val.getZExtValue())) {
|
||||
assert(SN->isTruncatingStore() &&
|
||||
"Non-truncating store and immediate value does not fit?");
|
||||
Val = Val.trunc(TotBytes * 8);
|
||||
}
|
||||
|
||||
SystemZVectorConstantInfo VCI(APInt(TotBytes * 8, Val.getZExtValue()));
|
||||
if (VCI.isVectorConstantLegal(Subtarget) &&
|
||||
VCI.Opcode == SystemZISD::REPLICATE) {
|
||||
Word = DAG.getConstant(VCI.OpVals[0], SDLoc(SN), MVT::i32);
|
||||
|
||||
26
llvm/test/CodeGen/SystemZ/dag-combine-07.ll
Normal file
26
llvm/test/CodeGen/SystemZ/dag-combine-07.ll
Normal file
@@ -0,0 +1,26 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
|
||||
; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z16 | FileCheck %s
|
||||
;
|
||||
; Test that SystemZTargetLowering::combineSTORE() does not crash on a
|
||||
; truncated immediate.
|
||||
|
||||
@G1 = external global i64, align 8
|
||||
@G2 = external global i64, align 8
|
||||
|
||||
define void @func_5(ptr %Dst) {
|
||||
; CHECK-LABEL: func_5:
|
||||
; CHECK: # %bb.0:
|
||||
; CHECK-NEXT: lgrl %r1, G2@GOT
|
||||
; CHECK-NEXT: llihl %r0, 50
|
||||
; CHECK-NEXT: oill %r0, 2
|
||||
; CHECK-NEXT: stg %r0, 0(%r1)
|
||||
; CHECK-NEXT: lgrl %r1, G1@GOT
|
||||
; CHECK-NEXT: stg %r0, 0(%r1)
|
||||
; CHECK-NEXT: mvhi 0(%r2), 2
|
||||
; CHECK-NEXT: br %r14
|
||||
store i64 214748364802, ptr @G2, align 8
|
||||
store i64 214748364802, ptr @G1, align 8
|
||||
%1 = load i32, ptr getelementptr inbounds (i8, ptr @G1, i64 4), align 4
|
||||
store i32 %1, ptr %Dst, align 4
|
||||
ret void
|
||||
}
|
||||
Reference in New Issue
Block a user