Skip to content

Commit 0ff5281

Browse files
[GlobalISel] Treat shift amounts as unsigned in matchShiftImmedChain
A miscompilation issue in the GISel pre-legalization phase has been addressed with improved routines. Fixes: #71440.
1 parent d9962c4 commit 0ff5281

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ bool CombinerHelper::matchShiftImmedChain(MachineInstr &MI,
15571557

15581558
// Pass the combined immediate to the apply function.
15591559
MatchInfo.Imm =
1560-
(MaybeImmVal->Value.getSExtValue() + MaybeImm2Val->Value).getSExtValue();
1560+
(MaybeImmVal->Value.getZExtValue() + MaybeImm2Val->Value).getZExtValue();
15611561
MatchInfo.Reg = Base;
15621562

15631563
// There is no simple replacement for a saturating unsigned left shift that

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,28 @@ body: |
463463
RET_ReallyLR implicit $x0
464464
465465
...
466+
---
467+
name: udiv_of_sext
468+
alignment: 4
469+
tracksRegLiveness: true
470+
liveins:
471+
- { reg: '$w0' }
472+
body: |
473+
bb.1:
474+
liveins: $w0
475+
476+
; CHECK-LABEL: name: udiv_of_sext
477+
; CHECK: liveins: $w0
478+
; CHECK-NEXT: {{ $}}
479+
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
480+
; CHECK-NEXT: $w0 = COPY [[C]](s32)
481+
; CHECK-NEXT: RET_ReallyLR implicit $w0
482+
%2:_(s1) = G_CONSTANT i1 true
483+
%4:_(s2) = G_CONSTANT i2 1
484+
%3:_(s2) = G_SEXT %2:_(s1)
485+
%5:_(s2) = G_UDIV %4:_, %3:_
486+
%6:_(s32) = G_ANYEXT %5:_(s2)
487+
$w0 = COPY %6:_(s32)
488+
RET_ReallyLR implicit $w0
489+
490+
...

0 commit comments

Comments
 (0)