Hi! abs_hwi asserts that the argument is not HOST_WIDE_INT_MIN and as the (invalid) testcase shows, the function can be called with such an offset. The following patch is IMHO minimal fix, absu_hwi unlike abs_hwi allows even that value and will return (unsigned HOST_WIDE_INT) HOST_WIDE_INT_MIN in that case. The function then uses moffset in two spots which wouldn't care if the value is (unsigned HOST_WIDE_INT) HOST_WIDE_INT_MIN or HOST_WIDE_INT_MIN and wouldn't accept it (!moffset and aarch64_uimm12_shift (moffset)), then in one spot where the signedness of moffset does matter and using unsigned is the right thing - moffset < 0x1000000 - and finally has code which will handle even this value right; the assembler doesn't really care for DImode immediates if mov x1, -9223372036854775808 or mov x1, 9223372036854775808 is used and similarly it doesn't matter if we add or sub it in DImode.
Bootstrapped/regtested on aarch64-linux, ok for trunk? 2020-03-10 Jakub Jelinek <ja...@redhat.com> PR target/94121 * config/aarch64/aarch64.c (aarch64_add_offset_1): Use absu_hwi instead of abs_hwi, change moffset type to unsigned HOST_WIDE_INT. * gcc.dg/pr94121.c: New test. --- gcc/config/aarch64/aarch64.c.jj 2020-02-28 17:33:03.414258503 +0100 +++ gcc/config/aarch64/aarch64.c 2020-03-10 17:01:39.435302124 +0100 @@ -3713,7 +3713,7 @@ aarch64_add_offset_1 (scalar_int_mode mo gcc_assert (emit_move_imm || temp1 != NULL_RTX); gcc_assert (temp1 == NULL_RTX || !reg_overlap_mentioned_p (temp1, src)); - HOST_WIDE_INT moffset = abs_hwi (offset); + unsigned HOST_WIDE_INT moffset = absu_hwi (offset); rtx_insn *insn; if (!moffset) --- gcc/testsuite/gcc.dg/pr94121.c.jj 2020-03-10 16:58:40.246974306 +0100 +++ gcc/testsuite/gcc.dg/pr94121.c 2020-03-10 16:58:40.246974306 +0100 @@ -0,0 +1,16 @@ +/* PR target/94121 */ +/* { dg-do compile { target pie } } */ +/* { dg-options "-O2 -fpie -w" } */ + +#define DIFF_MAX __PTRDIFF_MAX__ +#define DIFF_MIN (-DIFF_MAX - 1) + +extern void foo (char *); +extern char v[]; + +void +bar (void) +{ + char *p = v; + foo (&p[DIFF_MIN]); +} Jakub