File tree Expand file tree Collapse file tree 2 files changed +37
-8
lines changed
test/CodeGen/AArch64/GlobalISel Expand file tree Collapse file tree 2 files changed +37
-8
lines changed Original file line number Diff line number Diff line change @@ -6276,14 +6276,15 @@ bool CombinerHelper::matchShiftsTooBig(MachineInstr &MI) {
6276
6276
bool CombinerHelper::matchCommuteConstantToRHS (MachineInstr &MI) {
6277
6277
Register LHS = MI.getOperand (1 ).getReg ();
6278
6278
Register RHS = MI.getOperand (2 ).getReg ();
6279
- auto *LHSDef = MRI.getVRegDef (LHS);
6280
- if (getIConstantVRegVal (LHS, MRI).has_value ())
6281
- return true ;
6282
-
6283
- // LHS may be a G_CONSTANT_FOLD_BARRIER. If so we commute
6284
- // as long as we don't already have a constant on the RHS.
6285
- if (LHSDef->getOpcode () != TargetOpcode::G_CONSTANT_FOLD_BARRIER)
6286
- return false ;
6279
+ if (!getIConstantVRegVal (LHS, MRI)) {
6280
+ // Skip commuting if LHS is not a constant. But, LHS may be a
6281
+ // G_CONSTANT_FOLD_BARRIER. If so we commute as long as we don't already
6282
+ // have a constant on the RHS.
6283
+ if (MRI.getVRegDef (LHS)->getOpcode () !=
6284
+ TargetOpcode::G_CONSTANT_FOLD_BARRIER)
6285
+ return false ;
6286
+ }
6287
+ // Commute as long as RHS is not a constant or G_CONSTANT_FOLD_BARRIER.
6287
6288
return MRI.getVRegDef (RHS)->getOpcode () !=
6288
6289
TargetOpcode::G_CONSTANT_FOLD_BARRIER &&
6289
6290
!getIConstantVRegVal (RHS, MRI);
Original file line number Diff line number Diff line change
1
+ # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
2
+ # RUN: llc -mtriple aarch64 -run-pass=aarch64-prelegalizer-combiner %s -o - \
3
+ # RUN: --aarch64prelegalizercombiner-disable-rule=constant_fold_binop | FileCheck %s
4
+
5
+ # `constant_fold_binop` is disabled to trigger the infinite loop in `commute_int_constant_to_rhs`.
6
+
7
+ ---
8
+ name : add
9
+ tracksRegLiveness : true
10
+ body : |
11
+ bb.0:
12
+ liveins: $s0
13
+
14
+ ; CHECK-LABEL: name: add
15
+ ; CHECK: liveins: $s0
16
+ ; CHECK-NEXT: {{ $}}
17
+ ; CHECK-NEXT: %c0:_(s32) = G_CONSTANT i32 1
18
+ ; CHECK-NEXT: %c1:_(s32) = G_CONSTANT i32 2
19
+ ; CHECK-NEXT: %add:_(s32) = G_ADD %c0, %c1
20
+ ; CHECK-NEXT: $s0 = COPY %add(s32)
21
+ ; CHECK-NEXT: RET_ReallyLR
22
+ %c0:_(s32) = G_CONSTANT i32 1
23
+ %c1:_(s32) = G_CONSTANT i32 2
24
+ %add:_(s32) = G_ADD %c0, %c1
25
+ $s0 = COPY %add
26
+ RET_ReallyLR
27
+
28
+ ...
You can’t perform that action at this time.
0 commit comments