Skip to content

Commit ab4be2b

Browse files
authored
ISLE: Resolve overlaps in the aarch64 backend (#4988)
1 parent c1d6ca4 commit ab4be2b

File tree

3 files changed

+239
-237
lines changed

3 files changed

+239
-237
lines changed

cranelift/codegen/src/isa/aarch64/inst.isle

+45-45
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@
11371137

11381138
;; Helper for calculating the `OperandSize` corresponding to a type
11391139
(decl operand_size (Type) OperandSize)
1140-
(rule (operand_size (fits_in_32 _ty)) (OperandSize.Size32))
1140+
(rule 1 (operand_size (fits_in_32 _ty)) (OperandSize.Size32))
11411141
(rule (operand_size (fits_in_64 _ty)) (OperandSize.Size64))
11421142

11431143
(type ScalarSize extern
@@ -1167,10 +1167,10 @@
11671167

11681168
;; Helper for calculating the `ScalarSize` lane type from vector type
11691169
(decl lane_size (Type) ScalarSize)
1170-
(rule (lane_size (multi_lane 8 _)) (ScalarSize.Size8))
1171-
(rule (lane_size (multi_lane 16 _)) (ScalarSize.Size16))
1172-
(rule (lane_size (multi_lane 32 _)) (ScalarSize.Size32))
1173-
(rule (lane_size (multi_lane 64 _)) (ScalarSize.Size64))
1170+
(rule 1 (lane_size (multi_lane 8 _)) (ScalarSize.Size8))
1171+
(rule 1 (lane_size (multi_lane 16 _)) (ScalarSize.Size16))
1172+
(rule 1 (lane_size (multi_lane 32 _)) (ScalarSize.Size32))
1173+
(rule 1 (lane_size (multi_lane 64 _)) (ScalarSize.Size64))
11741174
(rule (lane_size (dynamic_lane 8 _)) (ScalarSize.Size8))
11751175
(rule (lane_size (dynamic_lane 16 _)) (ScalarSize.Size16))
11761176
(rule (lane_size (dynamic_lane 32 _)) (ScalarSize.Size32))
@@ -1209,13 +1209,13 @@
12091209

12101210
;; Helper for calculating the `VectorSize` corresponding to a type
12111211
(decl vector_size (Type) VectorSize)
1212-
(rule (vector_size (multi_lane 8 8)) (VectorSize.Size8x8))
1213-
(rule (vector_size (multi_lane 8 16)) (VectorSize.Size8x16))
1214-
(rule (vector_size (multi_lane 16 4)) (VectorSize.Size16x4))
1215-
(rule (vector_size (multi_lane 16 8)) (VectorSize.Size16x8))
1216-
(rule (vector_size (multi_lane 32 2)) (VectorSize.Size32x2))
1217-
(rule (vector_size (multi_lane 32 4)) (VectorSize.Size32x4))
1218-
(rule (vector_size (multi_lane 64 2)) (VectorSize.Size64x2))
1212+
(rule 1 (vector_size (multi_lane 8 8)) (VectorSize.Size8x8))
1213+
(rule 1 (vector_size (multi_lane 8 16)) (VectorSize.Size8x16))
1214+
(rule 1 (vector_size (multi_lane 16 4)) (VectorSize.Size16x4))
1215+
(rule 1 (vector_size (multi_lane 16 8)) (VectorSize.Size16x8))
1216+
(rule 1 (vector_size (multi_lane 32 2)) (VectorSize.Size32x2))
1217+
(rule 1 (vector_size (multi_lane 32 4)) (VectorSize.Size32x4))
1218+
(rule 1 (vector_size (multi_lane 64 2)) (VectorSize.Size64x2))
12191219
(rule (vector_size (dynamic_lane 8 8)) (VectorSize.Size8x8))
12201220
(rule (vector_size (dynamic_lane 8 16)) (VectorSize.Size8x16))
12211221
(rule (vector_size (dynamic_lane 16 4)) (VectorSize.Size16x4))
@@ -2113,7 +2113,7 @@
21132113
(let ((dst WritableReg (temp_writable_reg $I8X16))
21142114
(_ Unit (emit (MInst.FpuMove128 dst src))))
21152115
dst))
2116-
(rule (fpu_move (fits_in_64 _) src)
2116+
(rule 1 (fpu_move (fits_in_64 _) src)
21172117
(let ((dst WritableReg (temp_writable_reg $F64))
21182118
(_ Unit (emit (MInst.FpuMove64 dst src))))
21192119
dst))
@@ -2245,7 +2245,7 @@
22452245

22462246
;; Helper for generating `MInst.CCmpImm` instructions.
22472247
(decl ccmp_imm (OperandSize u8 Reg UImm5 NZCV Cond) ConsumesFlags)
2248-
(rule (ccmp_imm size 1 rn imm nzcv cond)
2248+
(rule 1 (ccmp_imm size 1 rn imm nzcv cond)
22492249
(let ((dst WritableReg (temp_writable_reg $I64)))
22502250
(ConsumesFlags.ConsumesFlagsTwiceReturnsValueRegs
22512251
(MInst.CCmpImm size rn imm nzcv cond)
@@ -2700,7 +2700,7 @@
27002700

27012701
;; Weird logical-instruction immediate in ORI using zero register; to simplify,
27022702
;; we only match when we are zero-extending the value.
2703-
(rule (imm (integral_ty ty) (ImmExtend.Zero) k)
2703+
(rule 1 (imm (integral_ty ty) (ImmExtend.Zero) k)
27042704
(if-let n (imm_logic_from_u64 ty k))
27052705
(orr_imm ty (zero_reg) n))
27062706

@@ -2715,7 +2715,7 @@
27152715

27162716
;; Place a `Value` into a register, sign extending it to 32-bits
27172717
(decl put_in_reg_sext32 (Value) Reg)
2718-
(rule (put_in_reg_sext32 val @ (value_type (fits_in_32 ty)))
2718+
(rule -1 (put_in_reg_sext32 val @ (value_type (fits_in_32 ty)))
27192719
(extend val $true (ty_bits ty) 32))
27202720

27212721
;; 32/64-bit passthrough.
@@ -2724,7 +2724,7 @@
27242724

27252725
;; Place a `Value` into a register, zero extending it to 32-bits
27262726
(decl put_in_reg_zext32 (Value) Reg)
2727-
(rule (put_in_reg_zext32 val @ (value_type (fits_in_32 ty)))
2727+
(rule -1 (put_in_reg_zext32 val @ (value_type (fits_in_32 ty)))
27282728
(extend val $false (ty_bits ty) 32))
27292729

27302730
;; 32/64-bit passthrough.
@@ -2733,15 +2733,15 @@
27332733

27342734
;; Place a `Value` into a register, sign extending it to 64-bits
27352735
(decl put_in_reg_sext64 (Value) Reg)
2736-
(rule (put_in_reg_sext64 val @ (value_type (fits_in_32 ty)))
2736+
(rule 1 (put_in_reg_sext64 val @ (value_type (fits_in_32 ty)))
27372737
(extend val $true (ty_bits ty) 64))
27382738

27392739
;; 64-bit passthrough.
27402740
(rule (put_in_reg_sext64 val @ (value_type $I64)) val)
27412741

27422742
;; Place a `Value` into a register, zero extending it to 64-bits
27432743
(decl put_in_reg_zext64 (Value) Reg)
2744-
(rule (put_in_reg_zext64 val @ (value_type (fits_in_32 ty)))
2744+
(rule 1 (put_in_reg_zext64 val @ (value_type (fits_in_32 ty)))
27452745
(extend val $false (ty_bits ty) 64))
27462746

27472747
;; 64-bit passthrough.
@@ -2755,7 +2755,7 @@
27552755
reg))
27562756

27572757
(decl size_from_ty (Type) OperandSize)
2758-
(rule (size_from_ty (fits_in_32 _ty)) (OperandSize.Size32))
2758+
(rule 1 (size_from_ty (fits_in_32 _ty)) (OperandSize.Size32))
27592759
(rule (size_from_ty $I64) (OperandSize.Size64))
27602760

27612761
;; Check for signed overflow. The only case is min_value / -1.
@@ -2790,29 +2790,29 @@
27902790
(decl alu_rs_imm_logic_commutative (ALUOp Type Value Value) Reg)
27912791

27922792
;; Base case of operating on registers.
2793-
(rule (alu_rs_imm_logic_commutative op ty x y)
2793+
(rule -1 (alu_rs_imm_logic_commutative op ty x y)
27942794
(alu_rrr op ty x y))
27952795

27962796
;; Special cases for when one operand is a constant.
27972797
(rule (alu_rs_imm_logic_commutative op ty x (iconst k))
27982798
(if-let imm (imm_logic_from_imm64 ty k))
27992799
(alu_rr_imm_logic op ty x imm))
2800-
(rule (alu_rs_imm_logic_commutative op ty (iconst k) x)
2800+
(rule 1 (alu_rs_imm_logic_commutative op ty (iconst k) x)
28012801
(if-let imm (imm_logic_from_imm64 ty k))
28022802
(alu_rr_imm_logic op ty x imm))
28032803

28042804
;; Special cases for when one operand is shifted left by a constant.
28052805
(rule (alu_rs_imm_logic_commutative op ty x (ishl y (iconst k)))
28062806
(if-let amt (lshl_from_imm64 ty k))
28072807
(alu_rrr_shift op ty x y amt))
2808-
(rule (alu_rs_imm_logic_commutative op ty (ishl x (iconst k)) y)
2808+
(rule 1 (alu_rs_imm_logic_commutative op ty (ishl x (iconst k)) y)
28092809
(if-let amt (lshl_from_imm64 ty k))
28102810
(alu_rrr_shift op ty y x amt))
28112811

28122812
;; Same as `alu_rs_imm_logic_commutative` above, except that it doesn't require
28132813
;; that the operation is commutative.
28142814
(decl alu_rs_imm_logic (ALUOp Type Value Value) Reg)
2815-
(rule (alu_rs_imm_logic op ty x y)
2815+
(rule -1 (alu_rs_imm_logic op ty x y)
28162816
(alu_rrr op ty x y))
28172817
(rule (alu_rs_imm_logic op ty x (iconst k))
28182818
(if-let imm (imm_logic_from_imm64 ty k))
@@ -2868,7 +2868,7 @@
28682868
(rule (load_addr (AMode.FPOffset 0 _)) (fp_reg))
28692869
(rule (load_addr (AMode.SPOffset 0 _)) (stack_reg))
28702870

2871-
(rule (load_addr addr)
2871+
(rule -1 (load_addr addr)
28722872
(let ((dst WritableReg (temp_writable_reg $I64))
28732873
(_ Unit (emit (MInst.LoadAddr dst addr))))
28742874
dst))
@@ -3044,7 +3044,7 @@
30443044
(mov_preg (preg_fp)))
30453045

30463046
(decl aarch64_link () Reg)
3047-
(rule (aarch64_link)
3047+
(rule 1 (aarch64_link)
30483048
(if (preserve_frame_pointers))
30493049
(if (sign_return_address_disabled))
30503050
(let ((dst WritableReg (temp_writable_reg $I64))
@@ -3081,7 +3081,7 @@
30813081
;; Helper for generating `fcopysign` instruction sequences.
30823082

30833083
(decl fcopy_sign (Reg Reg Type) Reg)
3084-
(rule (fcopy_sign x y (ty_scalar_float ty))
3084+
(rule 1 (fcopy_sign x y (ty_scalar_float ty))
30853085
(let ((dst WritableReg (temp_writable_reg $F64))
30863086
(tmp Reg (fpu_rri (fpu_op_ri_ushr (ty_bits ty) (max_shift ty)) y))
30873087
(_ Unit (emit (MInst.FpuRRIMod (fpu_op_ri_sli (ty_bits ty) (max_shift ty)) dst x tmp))))
@@ -3175,9 +3175,9 @@
31753175
;; Accepts the specific conversion op, the source register,
31763176
;; whether the input is signed, and finally the output type.
31773177
(decl fpu_to_int_cvt_sat (FpuToIntOp Reg bool Type) Reg)
3178-
(rule (fpu_to_int_cvt_sat op src _ $I64)
3178+
(rule 1 (fpu_to_int_cvt_sat op src _ $I64)
31793179
(fpu_to_int op src))
3180-
(rule (fpu_to_int_cvt_sat op src _ $I32)
3180+
(rule 1 (fpu_to_int_cvt_sat op src _ $I32)
31813181
(fpu_to_int op src))
31823182
(rule (fpu_to_int_cvt_sat op src $false (fits_in_16 out_ty))
31833183
(let ((result Reg (fpu_to_int op src))
@@ -3295,17 +3295,17 @@
32953295
(vec_rrr (VecALUOp.Fcmge) rm rn (vector_size ty)))
32963296

32973297
;; Integer
3298-
(rule (vec_cmp rn rm ty (Cond.Eq))
3298+
(rule 1 (vec_cmp rn rm ty (Cond.Eq))
32993299
(if (ty_vector_not_float ty))
33003300
(vec_rrr (VecALUOp.Cmeq) rn rm (vector_size ty)))
3301-
(rule (vec_cmp rn rm ty (Cond.Ne))
3301+
(rule 1 (vec_cmp rn rm ty (Cond.Ne))
33023302
(if (ty_vector_not_float ty))
33033303
(let ((tmp Reg (vec_rrr (VecALUOp.Cmeq) rn rm (vector_size ty))))
33043304
(vec_misc (VecMisc2.Not) tmp (vector_size ty))))
3305-
(rule (vec_cmp rn rm ty (Cond.Ge))
3305+
(rule 1 (vec_cmp rn rm ty (Cond.Ge))
33063306
(if (ty_vector_not_float ty))
33073307
(vec_rrr (VecALUOp.Cmge) rn rm (vector_size ty)))
3308-
(rule (vec_cmp rn rm ty (Cond.Gt))
3308+
(rule 1 (vec_cmp rn rm ty (Cond.Gt))
33093309
(if (ty_vector_not_float ty))
33103310
(vec_rrr (VecALUOp.Cmgt) rn rm (vector_size ty)))
33113311
(rule (vec_cmp rn rm ty (Cond.Hs))
@@ -3321,7 +3321,7 @@
33213321
(rule (vec_cmp rn rm ty (Cond.Lt))
33223322
(if (ty_vector_not_float ty))
33233323
(vec_rrr (VecALUOp.Cmgt) rm rn (vector_size ty)))
3324-
(rule (vec_cmp rn rm ty (Cond.Ls))
3324+
(rule 1 (vec_cmp rn rm ty (Cond.Ls))
33253325
(if (ty_vector_not_float ty))
33263326
(vec_rrr (VecALUOp.Cmhs) rm rn (vector_size ty)))
33273327
(rule (vec_cmp rn rm ty (Cond.Lo))
@@ -3336,7 +3336,7 @@
33363336
;; mov xm, vn.d[0]
33373337
;; cmp xm, #0
33383338
(decl vanytrue (Reg Type) ProducesFlags)
3339-
(rule (vanytrue src (ty_vec128 ty))
3339+
(rule 1 (vanytrue src (ty_vec128 ty))
33403340
(let ((src Reg (vec_rrr (VecALUOp.Umaxp) src src (VectorSize.Size32x4)))
33413341
(src Reg (mov_from_vec src 0 (ScalarSize.Size64))))
33423342
(cmp_imm (OperandSize.Size64) src (u8_into_imm12 0))))
@@ -3366,7 +3366,7 @@
33663366

33673367
;; Vectors.
33683368
;; `icmp` into flags for vectors is invalid.
3369-
(rule (lower_icmp_into_reg cond x y in_ty @ (multi_lane _ _) _out_ty)
3369+
(rule 1 (lower_icmp_into_reg cond x y in_ty @ (multi_lane _ _) _out_ty)
33703370
(let ((cond Cond (cond_code cond))
33713371
(rn Reg (put_in_reg x))
33723372
(rm Reg (put_in_reg y)))
@@ -3380,7 +3380,7 @@
33803380
(rule (lower_icmp_extend $I16 $false) (ExtendOp.UXTH))
33813381

33823382
;; Integers <= 64-bits.
3383-
(rule (lower_icmp_into_reg cond rn rm in_ty out_ty)
3383+
(rule -2 (lower_icmp_into_reg cond rn rm in_ty out_ty)
33843384
(if (ty_int_bool_ref_scalar_64 in_ty))
33853385
(let ((cc Cond (cond_code cond)))
33863386
(with_flags
@@ -3391,16 +3391,16 @@
33913391
(if (signed_cond_code cond))
33923392
(let ((rn Reg (put_in_reg_sext32 rn)))
33933393
(cmp_extend (operand_size ty) rn rm (lower_icmp_extend ty $true))))
3394-
(rule (lower_icmp cond rn (imm12_from_value rm) (fits_in_16 ty))
3394+
(rule -1 (lower_icmp cond rn (imm12_from_value rm) (fits_in_16 ty))
33953395
(let ((rn Reg (put_in_reg_zext32 rn)))
33963396
(cmp_imm (operand_size ty) rn rm)))
3397-
(rule -1 (lower_icmp cond rn rm (fits_in_16 ty))
3397+
(rule -2 (lower_icmp cond rn rm (fits_in_16 ty))
33983398
(let ((rn Reg (put_in_reg_zext32 rn)))
33993399
(cmp_extend (operand_size ty) rn rm (lower_icmp_extend ty $false))))
3400-
(rule -2 (lower_icmp cond rn (imm12_from_value rm) ty)
3400+
(rule -3 (lower_icmp cond rn (imm12_from_value rm) ty)
34013401
(if (ty_int_bool_ref_scalar_64 ty))
34023402
(cmp_imm (operand_size ty) rn rm))
3403-
(rule -3 (lower_icmp cond rn rm ty)
3403+
(rule -4 (lower_icmp cond rn rm ty)
34043404
(if (ty_int_bool_ref_scalar_64 ty))
34053405
(cmp (operand_size ty) rn rm))
34063406

@@ -3526,14 +3526,14 @@
35263526

35273527
;; Helpers for generating select instruction sequences.
35283528
(decl lower_select (ProducesFlags Cond Type Value Value) ValueRegs)
3529-
(rule (lower_select flags cond (ty_scalar_float ty) rn rm)
3529+
(rule 2 (lower_select flags cond (ty_scalar_float ty) rn rm)
35303530
(with_flags flags (fpu_csel ty cond rn rm)))
3531-
(rule (lower_select flags cond (ty_vec128 ty) rn rm)
3531+
(rule 3 (lower_select flags cond (ty_vec128 ty) rn rm)
35323532
(with_flags flags (vec_csel cond rn rm)))
35333533
(rule (lower_select flags cond ty rn rm)
35343534
(if (ty_vec64 ty))
35353535
(with_flags flags (fpu_csel $F64 cond rn rm)))
3536-
(rule (lower_select flags cond $I128 rn rm)
3536+
(rule 4 (lower_select flags cond $I128 rn rm)
35373537
(let ((dst_lo WritableReg (temp_writable_reg $I64))
35383538
(dst_hi WritableReg (temp_writable_reg $I64))
35393539
(rn ValueRegs (put_in_regs rn))
@@ -3547,7 +3547,7 @@
35473547
(MInst.CSel dst_lo cond rn_lo rm_lo)
35483548
(MInst.CSel dst_hi cond rn_hi rm_hi)
35493549
(value_regs dst_lo dst_hi)))))
3550-
(rule (lower_select flags cond ty rn rm)
3550+
(rule 1 (lower_select flags cond ty rn rm)
35513551
(if (ty_int_bool_ref_scalar_64 ty))
35523552
(with_flags flags (csel cond rn rm)))
35533553

0 commit comments

Comments
 (0)