[PATCH] D155284: [GlobalISel] Fix infinite loop in reassociation combine
Jay Foad via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 14 03:40:30 PDT 2023
foad created this revision.
foad added reviewers: AMDGPU, aemerson.
Herald added subscribers: StephenFan, kerbowa, hiraditya, jvesely.
Herald added a project: All.
foad requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Don't reassociate (C1 <https://reviews.llvm.org/C1>+C2)+Y -> C1 <https://reviews.llvm.org/C1>+(C2+Y).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D155284
Files:
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
llvm/test/CodeGen/AMDGPU/GlobalISel/postlegalizer-combiner-reassoc.mir
Index: llvm/test/CodeGen/AMDGPU/GlobalISel/postlegalizer-combiner-reassoc.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/GlobalISel/postlegalizer-combiner-reassoc.mir
@@ -0,0 +1,30 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 3
+# RUN: llc -global-isel -march=amdgcn -run-pass=amdgpu-postlegalizer-combiner -verify-machineinstrs -o - %s | FileCheck %s
+
+---
+name: test_reassoc_infinite_loop
+legalized: true
+tracksRegLiveness: true
+body: |
+ bb.1:
+ liveins: $vgpr0, $vgpr1, $vgpr2, $vgpr3, $vgpr4
+
+ ; CHECK-LABEL: name: test_reassoc_infinite_loop
+ ; CHECK: liveins: $vgpr0, $vgpr1, $vgpr2, $vgpr3, $vgpr4
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $vgpr0
+ ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
+ ; CHECK-NEXT: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY]], [[C]]
+ ; CHECK-NEXT: $vgpr0 = COPY [[ADD]](s32)
+ ; CHECK-NEXT: SI_RETURN implicit $vgpr0
+ %0:_(s32) = COPY $vgpr0
+ %7:_(s32) = G_CONSTANT i32 0
+ %13:_(s32) = G_CONSTANT i32 1
+ %46:_(s1) = G_ICMP intpred(eq), %7(s32), %7
+ %34:_(s32) = G_SELECT %46(s1), %13, %7
+ %14:_(s32) = COPY %34(s32)
+ %17:_(s32) = G_ADD %0, %14
+ %16:_(s32) = G_ADD %17, %13
+ $vgpr0 = COPY %16(s32)
+ SI_RETURN implicit $vgpr0
+...
Index: llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -4475,7 +4475,8 @@
Register OpLHSLHS = OpLHSDef->getOperand(1).getReg();
Register OpLHSRHS = OpLHSDef->getOperand(2).getReg();
- if (isConstantOrConstantSplatVector(*MRI.getVRegDef(OpLHSRHS), MRI)) {
+ if (isConstantOrConstantSplatVector(*MRI.getVRegDef(OpLHSRHS), MRI) &&
+ !isConstantOrConstantSplatVector(*MRI.getVRegDef(OpLHSLHS), MRI)) {
if (isConstantOrConstantSplatVector(*OpRHSDef, MRI)) {
// (Opc (Opc X, C1), C2) -> (Opc X, (Opc C1, C2))
MatchInfo = [=](MachineIRBuilder &B) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155284.540349.patch
Type: text/x-patch
Size: 2160 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230714/90b13376/attachment.bin>
More information about the llvm-commits
mailing list