From 53ebfa7c5d1bc121267dbf399b6386b2a3300d19 Mon Sep 17 00:00:00 2001 From: Amara Emerson Date: Mon, 11 Oct 2021 14:19:41 -0700 Subject: [PATCH] [AArch64][GlobalISel] Fix combiner assertion in matchConstantOp(). We shouldn't call APInt::getSExtValue() on a >64b value. --- llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | 3 ++- .../prelegalizercombiner-trivial-arith.mir | 23 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp index 2b8ff6a..a3b2cc4 100644 --- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp @@ -2370,7 +2370,8 @@ bool CombinerHelper::matchConstantOp(const MachineOperand &MOP, int64_t C) { return false; auto *MI = MRI.getVRegDef(MOP.getReg()); auto MaybeCst = isConstantOrConstantSplatVector(*MI, MRI); - return MaybeCst.hasValue() && MaybeCst->getSExtValue() == C; + return MaybeCst.hasValue() && MaybeCst->getBitWidth() <= 64 && + MaybeCst->getSExtValue() == C; } bool CombinerHelper::replaceSingleDefInstWithOperand(MachineInstr &MI, diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir b/llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir index 7bd325b..0681a3f3 100644 --- a/llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir +++ b/llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir @@ -410,3 +410,26 @@ body: | $q0 = COPY %ptr(<2 x p0>) RET_ReallyLR implicit $q0 ... +--- +name: i128_or_cst +liveins: + - { reg: '$x0' } +body: | + bb.1: + liveins: $x0 + + ; CHECK-LABEL: name: i128_or_cst + ; CHECK: [[COPY:%[0-9]+]]:_(p0) = COPY $x0 + ; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(s128) = G_LOAD [[COPY]](p0) :: (load (s128)) + ; CHECK-NEXT: [[C:%[0-9]+]]:_(s128) = G_CONSTANT i128 9223372036854775808 + ; CHECK-NEXT: [[OR:%[0-9]+]]:_(s128) = G_OR [[LOAD]], [[C]] + ; CHECK-NEXT: G_STORE [[OR]](s128), [[COPY]](p0) :: (store (s128), align 4) + ; CHECK-NEXT: RET_ReallyLR + %0:_(p0) = COPY $x0 + %2:_(s128) = G_LOAD %0(p0) :: (load (s128)) + %4:_(s128) = G_CONSTANT i128 9223372036854775808 + %5:_(s128) = G_OR %2, %4 + G_STORE %5(s128), %0(p0) :: (store (s128), align 4) + RET_ReallyLR + +... -- 2.7.4