The problem here is we don't check the return value of exact_log2
and always use that result as shifter. This fixes the issue by avoiding
the shift if the value was `-1` (which means the value was not exact a power of 
2);
in this case we could either check if the values was equal to -1 or not equal 
to because
we then assign -1 to shift if the constant value was not equal. I chose `!=` as
it seemed to be more obvious of what the code is doing.

Committed as obvious after a build/test for aarch64-linux-gnu.

gcc/ChangeLog:

        PR target/100212
        * config/aarch64/aarch64.cc (aarch64_classify_index): Avoid
        undefined shift after the call to exact_log2.

Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>
---
 gcc/config/aarch64/aarch64.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index d2014ce1527..19c608bc3ed 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -10246,7 +10246,9 @@ aarch64_classify_index (struct aarch64_address_info 
*info, rtx x,
       type = ADDRESS_REG_UXTW;
       index = XEXP (XEXP (x, 0), 0);
       shift = exact_log2 (INTVAL (XEXP (XEXP (x, 0), 1)));
-      if (INTVAL (XEXP (x, 1)) != (HOST_WIDE_INT)0xffffffff << shift)
+      /* Avoid undefined code dealing with shift being -1. */
+      if (shift != -1
+         && INTVAL (XEXP (x, 1)) != (HOST_WIDE_INT)0xffffffff << shift)
        shift = -1;
     }
   /* (and:DI (ashift:DI (reg:DI) (const_int shift))
-- 
2.39.3

Reply via email to