diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp --- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp +++ b/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) { diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/postlegalizer-combiner-reassoc.mir b/llvm/test/CodeGen/AMDGPU/GlobalISel/postlegalizer-combiner-reassoc.mir new file mode 100644 --- /dev/null +++ b/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 +...