Skip to content

Commit f85809c

Browse files
committed
[AArch64][SVE] Lower unpredicated loads/stores as LDR/STR.
Currently, given: ```cpp svuint8_t foo(uint8_t *x) { return svld1(svptrue_b8(), x); } ``` We generate: ```gas foo: ptrue p0.b ld1b { z0.b }, p0/z, [x0] ret ``` On little-endian, we could instead be using LDR as follows: ```gas foo: ldr z0, [x0] ret ``` The second form avoids the predicate dependency. Likewise for other types and stores.
1 parent 5f4d1f7 commit f85809c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2977,14 +2977,28 @@ let Predicates = [HasSVE_or_SME] in {
29772977
// Allow using the reg+reg form of ld1b/st1b for memory accesses with the
29782978
// same width as nxv16i8. This saves an add in cases where we would
29792979
// otherwise compute the address separately.
2980+
// Also allow using LDR/STR to avoid the predicate dependence.
29802981
multiclass unpred_loadstore_bitcast<ValueType Ty> {
29812982
let Predicates = [IsLE] in {
29822983
def : Pat<(Ty (load (am_sve_regreg_lsl0 GPR64sp:$base, GPR64:$offset))),
29832984
(LD1B (PTRUE_B 31), GPR64sp:$base, GPR64:$offset)>;
29842985
def : Pat<(store Ty:$val, (am_sve_regreg_lsl0 GPR64sp:$base, GPR64:$offset)),
29852986
(ST1B ZPR:$val, (PTRUE_B 31), GPR64sp:$base, GPR64:$offset)>;
2987+
2988+
let AddedComplexity = 2 in {
2989+
def : Pat<(Ty (load (am_sve_indexed_s9 GPR64sp:$base, simm9:$offset))),
2990+
(LDR_ZXI GPR64sp:$base, simm9:$offset)>;
2991+
def : Pat<(store Ty:$val, (am_sve_indexed_s9 GPR64sp:$base, simm9:$offset)),
2992+
(STR_ZXI ZPR:$val, GPR64sp:$base, simm9:$offset)>;
2993+
}
2994+
2995+
def : Pat<(Ty (load GPR64sp:$base)),
2996+
(LDR_ZXI GPR64sp:$base, (i64 0))>;
2997+
def : Pat<(store Ty:$val, GPR64sp:$base),
2998+
(STR_ZXI ZPR:$val, GPR64sp:$base, (i64 0))>;
29862999
}
29873000
}
3001+
defm : unpred_loadstore_bitcast<nxv16i8>;
29883002
defm : unpred_loadstore_bitcast<nxv8i16>;
29893003
defm : unpred_loadstore_bitcast<nxv8f16>;
29903004
defm : unpred_loadstore_bitcast<nxv8bf16>;

llvm/lib/Target/AArch64/SVEInstrFormats.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9668,6 +9668,7 @@ multiclass sve_int_perm_bin_perm_128_zz<bits<2> opc, bit P, string asm, SDPatter
96689668
let WantsRoot = true in {
96699669
def am_sve_indexed_s4 : ComplexPattern<iPTR, 2, "SelectAddrModeIndexedSVE<-8, 7>">;
96709670
def am_sve_indexed_s6 : ComplexPattern<iPTR, 2, "SelectAddrModeIndexedSVE<-32, 31>">;
9671+
def am_sve_indexed_s9 : ComplexPattern<iPTR, 2, "SelectAddrModeIndexedSVE<-256, 255>">;
96719672
}
96729673

96739674
def am_sve_regreg_lsl0 : ComplexPattern<iPTR, 2, "SelectSVERegRegAddrMode<0>", []>;

0 commit comments

Comments
 (0)