[PATCH] D136433: [GlobalISel][AArch64] Fix miscompile caused by wrong G_ZEXT selection in GISel
chenglin.bi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 24 20:26:28 PDT 2022
bcl5980 updated this revision to Diff 470361.
bcl5980 edited the summary of this revision.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136433/new/
https://reviews.llvm.org/D136433
Files:
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
llvm/test/CodeGen/AArch64/pr58431.ll
Index: llvm/test/CodeGen/AArch64/pr58431.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/pr58431.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=aarch64-none-linux-gnu -global-isel -global-isel-abort=0 | FileCheck %s
+
+define i32 @f(i64 %0) {
+; CHECK-LABEL: f:
+; CHECK: // %bb.0:
+; CHECK-NEXT: mov w8, #10
+; CHECK-NEXT: mov w9, w0
+; CHECK-NEXT: udiv x10, x9, x8
+; CHECK-NEXT: msub x0, x10, x8, x9
+; CHECK-NEXT: // kill: def $w0 killed $w0 killed $x0
+; CHECK-NEXT: ret
+ %2 = trunc i64 %0 to i32
+ %3 = freeze i32 %2
+ %4 = zext i32 %3 to i64
+ %5 = urem i64 %4, 10
+ %6 = trunc i64 %5 to i32
+ ret i32 %6
+}
Index: llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
===================================================================
--- llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
+++ llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
@@ -3269,24 +3269,12 @@
// For the 32-bit -> 64-bit case, we can emit a mov (ORRWrs)
// + SUBREG_TO_REG.
- //
- // If we are zero extending from 32 bits to 64 bits, it's possible that
- // the instruction implicitly does the zero extend for us. In that case,
- // we only need the SUBREG_TO_REG.
if (IsGPR && SrcSize == 32 && DstSize == 64) {
- // Unlike with the G_LOAD case, we don't want to look through copies
- // here. (See isDef32.)
- MachineInstr *Def = MRI.getVRegDef(SrcReg);
- Register SubregToRegSrc = SrcReg;
-
- // Does the instruction implicitly zero extend?
- if (!Def || !isDef32(*Def)) {
- // No. Zero out using an OR.
- Register OrDst = MRI.createVirtualRegister(&AArch64::GPR32RegClass);
- const Register ZReg = AArch64::WZR;
- MIB.buildInstr(AArch64::ORRWrs, {OrDst}, {ZReg, SrcReg}).addImm(0);
- SubregToRegSrc = OrDst;
- }
+ Register SubregToRegSrc =
+ MRI.createVirtualRegister(&AArch64::GPR32RegClass);
+ const Register ZReg = AArch64::WZR;
+ MIB.buildInstr(AArch64::ORRWrs, {SubregToRegSrc}, {ZReg, SrcReg})
+ .addImm(0);
MIB.buildInstr(AArch64::SUBREG_TO_REG, {DefReg}, {})
.addImm(0)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136433.470361.patch
Type: text/x-patch
Size: 2373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221025/c6bacded/attachment.bin>
More information about the llvm-commits
mailing list