[llvm] 0ff5281 - [GlobalISel] Treat shift amounts as unsigned in `matchShiftImmedChain`
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 24 09:16:19 PST 2023
Author: Antonio Frighetto
Date: 2023-11-24T18:14:52+01:00
New Revision: 0ff5281c947a56bf81205c4758f713aacd006a2f
URL: https://github.com/llvm/llvm-project/commit/0ff5281c947a56bf81205c4758f713aacd006a2f
DIFF: https://github.com/llvm/llvm-project/commit/0ff5281c947a56bf81205c4758f713aacd006a2f.diff
LOG: [GlobalISel] Treat shift amounts as unsigned in `matchShiftImmedChain`
A miscompilation issue in the GISel pre-legalization
phase has been addressed with improved routines.
Fixes: https://github.com/llvm/llvm-project/issues/71440.
Added:
Modified:
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
index 51c268ab77c2220..c2a7c2d01188129 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -1557,7 +1557,7 @@ bool CombinerHelper::matchShiftImmedChain(MachineInstr &MI,
// Pass the combined immediate to the apply function.
MatchInfo.Imm =
- (MaybeImmVal->Value.getSExtValue() + MaybeImm2Val->Value).getSExtValue();
+ (MaybeImmVal->Value.getZExtValue() + MaybeImm2Val->Value).getZExtValue();
MatchInfo.Reg = Base;
// There is no simple replacement for a saturating unsigned left shift that
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir b/llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir
index fdc6211f37c7e01..0900dd4267a2e4e 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir
@@ -463,3 +463,28 @@ body: |
RET_ReallyLR implicit $x0
...
+---
+name: udiv_of_sext
+alignment: 4
+tracksRegLiveness: true
+liveins:
+ - { reg: '$w0' }
+body: |
+ bb.1:
+ liveins: $w0
+
+ ; CHECK-LABEL: name: udiv_of_sext
+ ; CHECK: liveins: $w0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
+ ; CHECK-NEXT: $w0 = COPY [[C]](s32)
+ ; CHECK-NEXT: RET_ReallyLR implicit $w0
+ %2:_(s1) = G_CONSTANT i1 true
+ %4:_(s2) = G_CONSTANT i2 1
+ %3:_(s2) = G_SEXT %2:_(s1)
+ %5:_(s2) = G_UDIV %4:_, %3:_
+ %6:_(s32) = G_ANYEXT %5:_(s2)
+ $w0 = COPY %6:_(s32)
+ RET_ReallyLR implicit $w0
+
+...
More information about the llvm-commits
mailing list