@@ -3425,6 +3425,22 @@ (define_insn "aarch64_faddp<mode>"
[(set_attr "type" "neon_fp_reduc_add_<stype><q>")]
)
+(define_peephole2
+ [(set (match_operand:<VEL> 0 "register_operand")
+ (vec_select:<VEL>
+ (match_operand:VHSDF 1 "register_operand")
+ (parallel [(match_operand 2 "const_int_operand")])))
+ (set (match_operand:<VEL> 3 "register_operand")
+ (plus:<VEL>
+ (match_dup 0)
+ (match_operand:<VEL> 5 "register_operand")))]
+ "TARGET_SIMD
+ && ENDIAN_LANE_N (<nunits>, INTVAL (operands[2])) == 1
+ && REGNO (operands[5]) == REGNO (operands[1])
+ && peep2_reg_dead_p (2, operands[0])"
+ [(set (match_dup 3) (unspec:<VEL> [(match_dup 1)] UNSPEC_FADDV))]
+)
+
(define_insn "reduc_plus_scal_<mode>"
[(set (match_operand:<VEL> 0 "register_operand" "=w")
(unspec:<VEL> [(match_operand:VDQV 1 "register_operand" "w")]
@@ -25372,6 +25372,29 @@ aarch_macro_fusion_pair_p (rtx_insn *prev, rtx_insn *curr)
}
}
+ /* Try to schedule vec_select and add together so the peephole works. */
+ if (simple_sets_p && REG_P (SET_DEST (prev_set)) && REG_P (SET_DEST (curr_set))
+ && GET_CODE (SET_SRC (prev_set)) == VEC_SELECT && GET_CODE (SET_SRC (curr_set)) == PLUS)
+ {
+ /* We're trying to match:
+ prev (vec_select) == (set (reg r0)
+ (vec_select (reg r1) n)
+ curr (plus) == (set (reg r2)
+ (plus (reg r0) (reg r1))) */
+ rtx prev_src = SET_SRC (prev_set);
+ rtx curr_src = SET_SRC (curr_set);
+ rtx parallel = XEXP (prev_src, 1);
+ auto idx
+ = ENDIAN_LANE_N (GET_MODE_NUNITS (GET_MODE (XEXP (prev_src, 0))), 1);
+ if (GET_CODE (parallel) == PARALLEL
+ && XVECLEN (parallel, 0) == 1
+ && known_eq (INTVAL (XVECEXP (parallel, 0, 0)), idx)
+ && GET_MODE (SET_DEST (prev_set)) == GET_MODE (curr_src)
+ && GET_MODE_INNER (GET_MODE (XEXP (prev_src, 0)))
+ == GET_MODE (XEXP (curr_src, 1)))
+ return true;
+ }
+
/* Fuse compare (CMP/CMN/TST/BICS) and conditional branch. */
if (aarch64_fusion_enabled_p (AARCH64_FUSE_CMP_BRANCH)
&& prev_set && curr_set && any_condjump_p (curr)