[PATCH] D130525: [GlobalISel] Fix miscompile of G_UREM + G_UDIV due to not checking for equality of the first operands of each.
Amara Emerson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 25 16:03:26 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5ae0472694f5: [GlobalISel] Fix miscompile of G_UREM + G_UDIV due to not checking for equality (authored by aemerson).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130525/new/
https://reviews.llvm.org/D130525
Files:
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
llvm/test/CodeGen/AArch64/GlobalISel/combine-udivrem-use-bug.mir
Index: llvm/test/CodeGen/AArch64/GlobalISel/combine-udivrem-use-bug.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/GlobalISel/combine-udivrem-use-bug.mir
@@ -0,0 +1,25 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -o - -mtriple=aarch64-unknown-unknown -run-pass=aarch64-prelegalizer-combiner -verify-machineinstrs %s | FileCheck %s
+# Check that we don't miscompile this into G_UDIVREM because of the different
+# first operands.
+---
+name: no_combine_divrem_different_src1
+body: |
+ bb.1:
+ liveins: $w0
+
+ ; CHECK-LABEL: name: no_combine_divrem_different_src1
+ ; CHECK: liveins: $w0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
+ ; CHECK-NEXT: [[UREM:%[0-9]+]]:_(s32) = G_UREM [[COPY]], [[COPY]]
+ ; CHECK-NEXT: [[UDIV:%[0-9]+]]:_(s32) = G_UDIV [[UREM]], [[COPY]]
+ ; CHECK-NEXT: $w0 = COPY [[UDIV]](s32)
+ ; CHECK-NEXT: RET_ReallyLR implicit $w0
+ %0:_(s32) = COPY $w0
+ %1:_(s32) = G_UREM %0, %0
+ %2:_(s32) = G_UDIV %1, %0
+ $w0 = COPY %2(s32)
+ RET_ReallyLR implicit $w0
+
+...
Index: llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -1142,7 +1142,8 @@
if (MI.getParent() == UseMI.getParent() &&
((IsDiv && UseMI.getOpcode() == RemOpcode) ||
(!IsDiv && UseMI.getOpcode() == DivOpcode)) &&
- matchEqualDefs(MI.getOperand(2), UseMI.getOperand(2))) {
+ matchEqualDefs(MI.getOperand(2), UseMI.getOperand(2)) &&
+ matchEqualDefs(MI.getOperand(1), UseMI.getOperand(1))) {
OtherMI = &UseMI;
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130525.447509.patch
Type: text/x-patch
Size: 1857 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220725/b0ea766f/attachment.bin>
More information about the llvm-commits
mailing list