-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AArch64] Optimize add/sub with immediate through MIPeepholeOpt
Fixes the build issue with D111034, whose goal was to optimize add/sub with long immediates. Optimize ([add|sub] r, imm) -> ([ADD|SUB] ([ADD|SUB] r, #imm0, lsl #12), #imm1), if imm == (imm0<<12)+imm1. and both imm0 and imm1 are non-zero 12-bit unsigned integers. Optimize ([add|sub] r, imm) -> ([SUB|ADD] ([SUB|ADD] r, #imm0, lsl #12), #imm1), if imm == -(imm0<<12)-imm1, and both imm0 and imm1 are non-zero 12-bit unsigned integers. The change which fixed the build issue in D111034 was the use of new virtual registers so that SSA form is maintained until deleting MI. Differential Revision: https://reviews.llvm.org/D117429
- Loading branch information
1 parent
4041354
commit 93deac2
Showing
4 changed files
with
302 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py | ||
# RUN: llc -run-pass=aarch64-mi-peephole-opt -o - -mtriple=aarch64-unknown-linux -verify-machineinstrs %s | FileCheck %s | ||
|
||
# Main intention is to verify machine instructions have valid register classes. | ||
# Use of UBFM[W|X]ri is used as an arbitrary instruction that requires GPR[32|64]RegClass. | ||
# If the ADD/SUB optimization generates invalid register classes, this test will fail. | ||
--- | ||
name: addi | ||
body: | | ||
bb.0.entry: | ||
liveins: $w0 | ||
; CHECK-LABEL: name: addi | ||
; CHECK: [[COPY:%[0-9]+]]:gpr32common = COPY $w0 | ||
; CHECK-NEXT: [[ADDWri:%[0-9]+]]:gpr32sp = ADDWri [[COPY]], 273, 12 | ||
; CHECK-NEXT: [[ADDWri1:%[0-9]+]]:gpr32common = ADDWri [[ADDWri]], 3549, 0 | ||
; CHECK-NEXT: [[UBFMWri:%[0-9]+]]:gpr32 = UBFMWri [[ADDWri1]], 28, 31 | ||
; CHECK-NEXT: $w0 = COPY [[UBFMWri]] | ||
; CHECK-NEXT: RET_ReallyLR implicit $w0 | ||
%0:gpr32 = COPY $w0 | ||
%1:gpr32 = MOVi32imm 1121757 | ||
%2:gpr32 = ADDWrr %0, %1 | ||
%3:gpr32 = UBFMWri %2, 28, 31 | ||
$w0 = COPY %3 | ||
RET_ReallyLR implicit $w0 | ||
... | ||
--- | ||
name: addl | ||
body: | | ||
bb.0.entry: | ||
liveins: $x0 | ||
; CHECK-LABEL: name: addl | ||
; CHECK: [[COPY:%[0-9]+]]:gpr64common = COPY $x0 | ||
; CHECK-NEXT: [[ADDXri:%[0-9]+]]:gpr64sp = ADDXri [[COPY]], 273, 12 | ||
; CHECK-NEXT: [[ADDXri1:%[0-9]+]]:gpr64common = ADDXri [[ADDXri]], 3549, 0 | ||
; CHECK-NEXT: [[UBFMXri:%[0-9]+]]:gpr64 = UBFMXri [[ADDXri1]], 28, 31 | ||
; CHECK-NEXT: $x0 = COPY [[UBFMXri]] | ||
; CHECK-NEXT: RET_ReallyLR implicit $x0 | ||
%0:gpr64 = COPY $x0 | ||
%1:gpr32 = MOVi32imm 1121757 | ||
%2:gpr64 = SUBREG_TO_REG 0, %1, %subreg.sub_32 | ||
%3:gpr64 = ADDXrr %0, killed %2 | ||
%4:gpr64 = UBFMXri %3, 28, 31 | ||
$x0 = COPY %4 | ||
RET_ReallyLR implicit $x0 | ||
... | ||
--- | ||
name: addl_negate | ||
body: | | ||
bb.0.entry: | ||
liveins: $x0 | ||
; CHECK-LABEL: name: addl_negate | ||
; CHECK: [[COPY:%[0-9]+]]:gpr64common = COPY $x0 | ||
; CHECK-NEXT: [[SUBXri:%[0-9]+]]:gpr64sp = SUBXri [[COPY]], 273, 12 | ||
; CHECK-NEXT: [[SUBXri1:%[0-9]+]]:gpr64common = SUBXri [[SUBXri]], 3549, 0 | ||
; CHECK-NEXT: [[UBFMXri:%[0-9]+]]:gpr64 = UBFMXri [[SUBXri1]], 28, 31 | ||
; CHECK-NEXT: $x0 = COPY [[UBFMXri]] | ||
; CHECK-NEXT: RET_ReallyLR implicit $x0 | ||
%0:gpr64 = COPY $x0 | ||
%1:gpr64 = MOVi64imm -1121757 | ||
%2:gpr64 = ADDXrr %0, killed %1 | ||
%3:gpr64 = UBFMXri %2, 28, 31 | ||
$x0 = COPY %3 | ||
RET_ReallyLR implicit $x0 |
Oops, something went wrong.