diff options
author | Andre Vieira <andre.simoesdiasvieira@arm.com> | 2024-10-02 15:14:40 +0100 |
---|---|---|
committer | Andre Vieira <andre.simoesdiasvieira@arm.com> | 2024-10-02 15:15:47 +0100 |
commit | 4e11ad7c345b6084ffe45ac569352dd316ee5cc6 (patch) | |
tree | e0be8894fe1d7326a54be88c6c74f2768b11e38e /gcc/config/arm/arm.cc | |
parent | 3a528386571fffbb41703a238aee950043af3f3c (diff) | |
download | gcc-4e11ad7c345b6084ffe45ac569352dd316ee5cc6.zip gcc-4e11ad7c345b6084ffe45ac569352dd316ee5cc6.tar.gz gcc-4e11ad7c345b6084ffe45ac569352dd316ee5cc6.tar.bz2 |
arm: Prevent ICE when doloop dec_set is not PLUS expr
This patch refactors and fixes an issue where arm_mve_dlstp_check_dec_counter
was making an assumption about the form of what a candidate for a dec_insn
should be, which caused an ICE.
This dec_insn is the instruction that decreases the loop counter inside a
decrementing loop and we expect it to have the following form:
(set (reg CONDCOUNT)
(plus (reg CONDCOUNT)
(const_int)))
Where CONDCOUNT is the loop counter, and const int is the negative constant
used to decrement it.
This patch also improves our search for a valid dec_insn. Before this patch
we'd only look for a dec_insn inside the loop header if the loop latch was
empty. We now also search the loop header if the loop latch is not empty but
the last instruction is not a valid dec_insn. This could potentially be improved
to search all instructions inside the loop latch.
gcc/ChangeLog:
* config/arm/arm.cc (check_dec_insn): New helper function containing
code hoisted from...
(arm_mve_dlstp_check_dec_counter): ... here. Use check_dec_insn to
check the validity of the candidate dec_insn.
gcc/testsuite/ChangeLog:
* gcc.target/arm/mve/dlstp-loop-form.c: New test.
Diffstat (limited to 'gcc/config/arm/arm.cc')
-rw-r--r-- | gcc/config/arm/arm.cc | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc index de34e98..62eea50 100644 --- a/gcc/config/arm/arm.cc +++ b/gcc/config/arm/arm.cc @@ -35231,6 +35231,32 @@ arm_mve_dlstp_check_inc_counter (loop *loop, rtx_insn* vctp_insn, return vctp_insn; } +/* Helper function to 'arm_mve_dlstp_check_dec_counter' to make sure DEC_INSN + is of the expected form: + (set (reg a) (plus (reg a) (const_int))) + where (reg a) is the same as CONDCOUNT. + Return a rtx with the set if it is in the right format or NULL_RTX + otherwise. */ + +static rtx +check_dec_insn (rtx_insn *dec_insn, rtx condcount) +{ + if (!NONDEBUG_INSN_P (dec_insn)) + return NULL_RTX; + rtx dec_set = single_set (dec_insn); + if (!dec_set + || !REG_P (SET_DEST (dec_set)) + || GET_CODE (SET_SRC (dec_set)) != PLUS + || !REG_P (XEXP (SET_SRC (dec_set), 0)) + || !CONST_INT_P (XEXP (SET_SRC (dec_set), 1)) + || REGNO (SET_DEST (dec_set)) + != REGNO (XEXP (SET_SRC (dec_set), 0)) + || REGNO (SET_DEST (dec_set)) != REGNO (condcount)) + return NULL_RTX; + + return dec_set; +} + /* Helper function to `arm_mve_loop_valid_for_dlstp`. In the case of a counter that is decrementing, ensure that it is decrementing by the right amount in each iteration and that the target condition is what @@ -35247,30 +35273,19 @@ arm_mve_dlstp_check_dec_counter (loop *loop, rtx_insn* vctp_insn, loop latch. Here we simply need to verify that this counter is the same reg that is also used in the vctp_insn and that it is not otherwise modified. */ - rtx_insn *dec_insn = BB_END (loop->latch); + rtx dec_set = check_dec_insn (BB_END (loop->latch), condcount); /* If not in the loop latch, try to find the decrement in the loop header. */ - if (!NONDEBUG_INSN_P (dec_insn)) + if (dec_set == NULL_RTX) { df_ref temp = df_bb_regno_only_def_find (loop->header, REGNO (condcount)); /* If we haven't been able to find the decrement, bail out. */ if (!temp) return NULL; - dec_insn = DF_REF_INSN (temp); - } - - rtx dec_set = single_set (dec_insn); + dec_set = check_dec_insn (DF_REF_INSN (temp), condcount); - /* Next, ensure that it is a PLUS of the form: - (set (reg a) (plus (reg a) (const_int))) - where (reg a) is the same as condcount. */ - if (!dec_set - || !REG_P (SET_DEST (dec_set)) - || !REG_P (XEXP (SET_SRC (dec_set), 0)) - || !CONST_INT_P (XEXP (SET_SRC (dec_set), 1)) - || REGNO (SET_DEST (dec_set)) - != REGNO (XEXP (SET_SRC (dec_set), 0)) - || REGNO (SET_DEST (dec_set)) != REGNO (condcount)) - return NULL; + if (dec_set == NULL_RTX) + return NULL; + } decrementnum = INTVAL (XEXP (SET_SRC (dec_set), 1)); |