Skip to content

Commit 7472490

Browse files
authored
[AArch64] Split Ampere1Write_Arith into rr/ri and rs/rx InstRWs. (#66384)
The ampere1 scheduling model uses IsCheapLSL predicates for ADDXri and ADDWrr instructions, which only have 3 operands. In attempting to check that the third is a shift, the predicate can attempt to access an out of bounds operand, hitting an assert. This splits the rr/ri instructions (which can never have shifts) from the rs/rx instructions to ensure they both work correctly. Ampere1Write_1cyc_1AB was chosen for the rr/ir instructions to match the cheap case. This also sets CompleteModel = 0 for the ampere1 scheduling model, as at runtime under debug it will attempt to check that as well as all instructions having scheduling info, there is information for each output operand. DefIdx 1 exceeds machine model writes for renamable $w9, renamable $w8 = LDPWi renamable $x8, 0 (Try with MCSchedModel.CompleteModel set to false)incomplete machine model
1 parent 360c629 commit 7472490

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

llvm/lib/Target/AArch64/AArch64SchedAmpere1.td

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def Ampere1Model : SchedMachineModel {
2222
let LoadLatency = 4; // Optimistic load latency
2323
let MispredictPenalty = 10; // Branch mispredict penalty
2424
let LoopMicroOpBufferSize = 32; // Instruction queue size
25-
let CompleteModel = 1;
25+
let CompleteModel = 0;
2626

2727
list<Predicate> UnsupportedFeatures = !listconcat(SVEUnsupported.F,
2828
SMEUnsupported.F,
@@ -936,9 +936,13 @@ def : InstRW<[Ampere1Write_4cyc_1Z], (instregex "^FMOV[WX][HSD]r")>;
936936
def : InstRW<[Ampere1Write_1cyc_1A],
937937
(instregex "ADC(W|X)r", "SBC(W|X)r")>;
938938
def : InstRW<[Ampere1Write_Arith],
939-
(instregex "(ADD|AND|BIC|EON|EOR|ORN|ORR|SUB)(W|X)r")>;
939+
(instregex "(ADD|AND|BIC|EON|EOR|ORN|ORR|SUB)(W|X)r[sx]")>;
940+
def : InstRW<[Ampere1Write_1cyc_1AB],
941+
(instregex "(ADD|AND|BIC|EON|EOR|ORN|ORR|SUB)(W|X)r[ri]")>;
940942
def : InstRW<[Ampere1Write_ArithFlagsetting],
941-
(instregex "(ADD|AND|BIC|SUB)S(W|X)r")>;
943+
(instregex "(ADD|AND|BIC|SUB)S(W|X)r[sx]")>;
944+
def : InstRW<[Ampere1Write_1cyc_1A],
945+
(instregex "(ADD|AND|BIC|SUB)S(W|X)r[ri]")>;
942946
def : InstRW<[Ampere1Write_1cyc_1A],
943947
(instregex "(ADC|SBC)S(W|X)r")>;
944948
def : InstRW<[Ampere1Write_1cyc_1A], (instrs RMIF)>;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 3
2+
# RUN: llc -run-pass=machine-scheduler %s -o - | FileCheck %s
3+
4+
--- |
5+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
6+
target triple = "aarch64"
7+
8+
define i32 @test_add(ptr %0) #0 {
9+
%2 = ptrtoint ptr %0 to i64
10+
%3 = and i64 %2, -64
11+
%4 = inttoptr i64 %3 to ptr
12+
%5 = load i32, ptr %4, align 64
13+
%6 = getelementptr inbounds i32, ptr %4, i64 1
14+
%7 = load i32, ptr %6, align 4
15+
%8 = add nsw i32 %7, %5
16+
ret i32 %8
17+
}
18+
19+
attributes #0 = { "target-cpu"="ampere1" }
20+
21+
...
22+
---
23+
name: test_add
24+
tracksRegLiveness: true
25+
registers:
26+
- { id: 0, class: gpr64, preferred-register: '' }
27+
- { id: 1, class: gpr64sp, preferred-register: '' }
28+
- { id: 2, class: gpr32, preferred-register: '' }
29+
- { id: 3, class: gpr32, preferred-register: '' }
30+
- { id: 4, class: gpr32, preferred-register: '' }
31+
liveins:
32+
- { reg: '$x0', virtual-reg: '%0' }
33+
body: |
34+
bb.0 (%ir-block.1):
35+
liveins: $x0
36+
37+
; CHECK-LABEL: name: test_add
38+
; CHECK: liveins: $x0
39+
; CHECK-NEXT: {{ $}}
40+
; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr64 = COPY $x0
41+
; CHECK-NEXT: [[ANDXri:%[0-9]+]]:gpr64sp = ANDXri [[COPY]], 7865
42+
; CHECK-NEXT: [[LDRWui:%[0-9]+]]:gpr32 = LDRWui [[ANDXri]], 0 :: (load (s32) from %ir.4, align 64)
43+
; CHECK-NEXT: [[LDRWui1:%[0-9]+]]:gpr32 = LDRWui [[ANDXri]], 1 :: (load (s32) from %ir.6)
44+
; CHECK-NEXT: [[ADDWrr:%[0-9]+]]:gpr32 = nsw ADDWrr [[LDRWui1]], [[LDRWui]]
45+
; CHECK-NEXT: $w0 = COPY [[ADDWrr]]
46+
; CHECK-NEXT: RET_ReallyLR implicit $w0
47+
%0:gpr64 = COPY $x0
48+
%1:gpr64sp = ANDXri %0, 7865
49+
%2:gpr32 = LDRWui %1, 0 :: (load (s32) from %ir.4, align 64)
50+
%3:gpr32 = LDRWui %1, 1 :: (load (s32) from %ir.6)
51+
%4:gpr32 = nsw ADDWrr %3, %2
52+
$w0 = COPY %4
53+
RET_ReallyLR implicit $w0
54+
55+
...

0 commit comments

Comments
 (0)