aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGulfem Savrun Yeniceri <gulfem@google.com>2024-04-04 16:36:43 +0000
committerGulfem Savrun Yeniceri <gulfem@google.com>2024-04-04 16:39:31 +0000
commitbe8fd86f6a57da79a4dbc8d1f4dca2e7adb1192a (patch)
treeb839f2f4f9bc0124dafacb1d1d8ea00966ae995c
parentdcc45faa30041a3378bcde4857df205382f1996a (diff)
downloadllvm-be8fd86f6a57da79a4dbc8d1f4dca2e7adb1192a.zip
llvm-be8fd86f6a57da79a4dbc8d1f4dca2e7adb1192a.tar.gz
llvm-be8fd86f6a57da79a4dbc8d1f4dca2e7adb1192a.tar.bz2
Revert "[GlobalISel] Fix the infinite loop issue in `commute_int_constant_to_rhs`"
This reverts commit 1f01c580444ea2daef67f95ffc5fde2de5a37cec because combine-commute-int-const-lhs.mir test failed in multiple builders. https://lab.llvm.org/buildbot/#/builders/124/builds/10375 https://luci-milo.appspot.com/ui/p/fuchsia/builders/prod/clang-linux-x64/b8751607530180046481/overview
-rw-r--r--llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp17
-rw-r--r--llvm/test/CodeGen/AArch64/GlobalISel/combine-commute-int-const-lhs.mir28
2 files changed, 8 insertions, 37 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
index 719209e..e53e35d 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -6273,15 +6273,14 @@ bool CombinerHelper::matchShiftsTooBig(MachineInstr &MI) {
bool CombinerHelper::matchCommuteConstantToRHS(MachineInstr &MI) {
Register LHS = MI.getOperand(1).getReg();
Register RHS = MI.getOperand(2).getReg();
- if (!getIConstantVRegVal(LHS, MRI)) {
- // Skip commuting if LHS is not a constant. But, LHS may be a
- // G_CONSTANT_FOLD_BARRIER. If so we commute as long as we don't already
- // have a constant on the RHS.
- if (MRI.getVRegDef(LHS)->getOpcode() !=
- TargetOpcode::G_CONSTANT_FOLD_BARRIER)
- return false;
- }
- // Commute as long as RHS is not a constant or G_CONSTANT_FOLD_BARRIER.
+ auto *LHSDef = MRI.getVRegDef(LHS);
+ if (getIConstantVRegVal(LHS, MRI).has_value())
+ return true;
+
+ // LHS may be a G_CONSTANT_FOLD_BARRIER. If so we commute
+ // as long as we don't already have a constant on the RHS.
+ if (LHSDef->getOpcode() != TargetOpcode::G_CONSTANT_FOLD_BARRIER)
+ return false;
return MRI.getVRegDef(RHS)->getOpcode() !=
TargetOpcode::G_CONSTANT_FOLD_BARRIER &&
!getIConstantVRegVal(RHS, MRI);
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/combine-commute-int-const-lhs.mir b/llvm/test/CodeGen/AArch64/GlobalISel/combine-commute-int-const-lhs.mir
deleted file mode 100644
index b145a6d..0000000
--- a/llvm/test/CodeGen/AArch64/GlobalISel/combine-commute-int-const-lhs.mir
+++ /dev/null
@@ -1,28 +0,0 @@
-# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
-# RUN: llc -mtriple aarch64 -run-pass=aarch64-prelegalizer-combiner %s -o - \
-# RUN: --aarch64prelegalizercombiner-disable-rule=constant_fold_binop | FileCheck %s
-
-# `constant_fold_binop` is disabled to trigger the infinite loop in `commute_int_constant_to_rhs`.
-
----
-name: add
-tracksRegLiveness: true
-body: |
- bb.0:
- liveins: $s0
-
- ; CHECK-LABEL: name: add
- ; CHECK: liveins: $s0
- ; CHECK-NEXT: {{ $}}
- ; CHECK-NEXT: %c0:_(s32) = G_CONSTANT i32 1
- ; CHECK-NEXT: %c1:_(s32) = G_CONSTANT i32 2
- ; CHECK-NEXT: %add:_(s32) = G_ADD %c0, %c1
- ; CHECK-NEXT: $s0 = COPY %add(s32)
- ; CHECK-NEXT: RET_ReallyLR
- %c0:_(s32) = G_CONSTANT i32 1
- %c1:_(s32) = G_CONSTANT i32 2
- %add:_(s32) = G_ADD %c0, %c1
- $s0 = COPY %add
- RET_ReallyLR
-
-...