Skip to content

Commit 53ebfa7

Browse files
committed
[AArch64][GlobalISel] Fix combiner assertion in matchConstantOp().
We shouldn't call APInt::getSExtValue() on a >64b value.
1 parent c5fb1a0 commit 53ebfa7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2370,7 +2370,8 @@ bool CombinerHelper::matchConstantOp(const MachineOperand &MOP, int64_t C) {
23702370
return false;
23712371
auto *MI = MRI.getVRegDef(MOP.getReg());
23722372
auto MaybeCst = isConstantOrConstantSplatVector(*MI, MRI);
2373-
return MaybeCst.hasValue() && MaybeCst->getSExtValue() == C;
2373+
return MaybeCst.hasValue() && MaybeCst->getBitWidth() <= 64 &&
2374+
MaybeCst->getSExtValue() == C;
23742375
}
23752376

23762377
bool CombinerHelper::replaceSingleDefInstWithOperand(MachineInstr &MI,

llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,3 +410,26 @@ body: |
410410
$q0 = COPY %ptr(<2 x p0>)
411411
RET_ReallyLR implicit $q0
412412
...
413+
---
414+
name: i128_or_cst
415+
liveins:
416+
- { reg: '$x0' }
417+
body: |
418+
bb.1:
419+
liveins: $x0
420+
421+
; CHECK-LABEL: name: i128_or_cst
422+
; CHECK: [[COPY:%[0-9]+]]:_(p0) = COPY $x0
423+
; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(s128) = G_LOAD [[COPY]](p0) :: (load (s128))
424+
; CHECK-NEXT: [[C:%[0-9]+]]:_(s128) = G_CONSTANT i128 9223372036854775808
425+
; CHECK-NEXT: [[OR:%[0-9]+]]:_(s128) = G_OR [[LOAD]], [[C]]
426+
; CHECK-NEXT: G_STORE [[OR]](s128), [[COPY]](p0) :: (store (s128), align 4)
427+
; CHECK-NEXT: RET_ReallyLR
428+
%0:_(p0) = COPY $x0
429+
%2:_(s128) = G_LOAD %0(p0) :: (load (s128))
430+
%4:_(s128) = G_CONSTANT i128 9223372036854775808
431+
%5:_(s128) = G_OR %2, %4
432+
G_STORE %5(s128), %0(p0) :: (store (s128), align 4)
433+
RET_ReallyLR
434+
435+
...

0 commit comments

Comments
 (0)