https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98519

--- Comment #23 from Michael Meissner <meissner at gcc dot gnu.org> ---
Obviously one approach is to use the recog_data.is_asm field to determine if
the %m constraint is in an asm and restrict it to non-prefixed memory
addresses.

However, this doesn't work, because is_asm is not reliably set.

For example in this program:

static int x;
int *p_x = &x;

int get (void)
{
  int a;
  __asm__ ("lwz%U0%X0 %0,%1" : "=r" (a) : "m" (x));
  return a;
}

And we look at calls to satisfies_constraint_m, the is_asm field it not set for
each of the references:

Current directory is
/home/meissner/fsf-build-x86_64/work036-powerpc64le-linux/gcc/
GNU gdb (GDB) 11.0.50.20210212-git
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from
/home/meissner/fsf-build-x86_64/work036-powerpc64le-linux/gcc/cc1...
.gdbinit:14: Error in sourced command file:
/home/meissner/fsf-src/work036/gcc/gdbinit.in:323: Error in sourced command
file:
Python scripting is not supported in this copy of GDB.
(gdb) b ira.c:5527
Breakpoint 1 at 0xa10c45: file /home/meissner/fsf-src/work036/gcc/ira.c, line
5527.
# the above line is after the initial setup that IRA does.
(gdb) b satisfies_constraint_m
Breakpoint 2 at 0x1363e30: satisfies_constraint_m. (2 locations)
(gdb) dis 2
(gdb) commands 2
Type commands for breakpoint(s) 2, one per line.
End with a line saying just "end".
>print op
>pr
>print recog_data.is_asm
>(gdb) r -O2 -quiet -mcpu=power10 foo02.c

Starting program:
/home/meissner/fsf-build-x86_64/work036-powerpc64le-linux/gcc/cc1 -O2 -quiet
-mcpu=power10 foo02.c
Breakpoint 1, ira (f=0x0) at /home/meissner/fsf-src/work036/gcc/ira.c:5527
(gdb) en 2
(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at tm-constrs.h:10
$1 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$2 = false
# Note, is_asm should be true here

(gdb) where
#0  satisfies_constraint_m (op=0x7ffff0de35e8) at tm-constrs.h:10
#1  0x0000000000a59ba7 in constraint_satisfied_p (c=CONSTRAINT_m,
x=0x7ffff0de35e8) at ./tm-preds.h:258
#2  valid_address_p (op=op@entry=0x7ffff0de35e8, ad=ad@entry=0x7fffffffbc80,
constraint=constraint@entry=CONSTRAINT_m)
    at /home/meissner/fsf-src/work036/gcc/lra-constraints.c:415
#3  0x0000000000a612d6 in process_address_1 (nop=-17280,
check_only_p=<optimized out>, before=0x7fffffffbe50, after=<optimized out>)
    at /home/meissner/fsf-src/work036/gcc/lra-constraints.c:3531
#4  0x0000000000a63101 in process_address (after=0x7fffffffbe58,
before=0x7fffffffbe50, check_only_p=false, nop=1)
    at /home/meissner/fsf-src/work036/gcc/lra-constraints.c:3739
#5  curr_insn_transform (check_only_p=<optimized out>) at
/home/meissner/fsf-src/work036/gcc/lra-constraints.c:4054
#6  0x0000000000a681ee in lra_constraints (first_p=<optimized out>) at
/home/meissner/fsf-src/work036/gcc/lra-constraints.c:5143
#7  0x0000000000a5089b in lra (f=<optimized out>) at
/home/meissner/fsf-src/work036/gcc/lra.c:2336
#8  0x0000000000a0bcfa in do_reload () at
/home/meissner/fsf-src/work036/gcc/ira.c:5827
#9  (anonymous namespace)::pass_reload::execute (this=<optimized out>) at
/home/meissner/fsf-src/work036/gcc/ira.c:6013
#10 0x0000000000b133fd in execute_one_pass (pass=0x20b66c0) at
/home/meissner/fsf-src/work036/gcc/passes.c:2567
#11 0x0000000000b13da0 in execute_pass_list_1 (pass=0x20b66c0) at
/home/meissner/fsf-src/work036/gcc/passes.c:2656
#12 0x0000000000b13db2 in execute_pass_list_1 (pass=0x20b54c0) at
/home/meissner/fsf-src/work036/gcc/passes.c:2657
#13 0x0000000000b13dd9 in execute_pass_list (fn=0x7ffff0dd8000, pass=<optimized
out>) at /home/meissner/fsf-src/work036/gcc/passes.c:2667
#14 0x00000000007a34e1 in cgraph_node::expand (this=0x7ffff0fd6440) at
/home/meissner/fsf-src/work036/gcc/context.h:48
#15 0x00000000007a49f0 in expand_all_functions () at
/home/meissner/fsf-src/work036/gcc/cgraphunit.c:1995
#16 symbol_table::compile (this=0x7ffff0fce000) at
/home/meissner/fsf-src/work036/gcc/cgraphunit.c:2359
#17 0x00000000007a7398 in symbol_table::compile (this=0x7ffff0fce000) at
/home/meissner/fsf-src/work036/gcc/cgraphunit.c:2272
#18 symbol_table::finalize_compilation_unit (this=0x7ffff0fce000) at
/home/meissner/fsf-src/work036/gcc/cgraphunit.c:2540
#19 0x0000000000bed568 in compile_file () at
/home/meissner/fsf-src/work036/gcc/toplev.c:482
#20 0x00000000005f4a17 in do_compile () at
/home/meissner/fsf-src/work036/gcc/toplev.c:2197
#21 toplev::main (this=this@entry=0x7fffffffcdde, argc=<optimized out>,
argc@entry=5, argv=<optimized out>, argv@entry=0x7fffffffced8)
    at /home/meissner/fsf-src/work036/gcc/toplev.c:2336
#22 0x00000000005f73af in main (argc=5, argv=0x7fffffffced8) at
/home/meissner/fsf-src/work036/gcc/main.c:39

(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at
/home/meissner/fsf-src/work036/gcc/common.md:27
$3 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$4 = false
(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at tm-constrs.h:10
$5 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$6 = false
(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at
/home/meissner/fsf-src/work036/gcc/common.md:27
$7 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$8 = false
(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at tm-constrs.h:10
$9 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$10 = true
(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at
/home/meissner/fsf-src/work036/gcc/common.md:27
$11 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$12 = true
(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at tm-constrs.h:10
$13 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$14 = true
(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at
/home/meissner/fsf-src/work036/gcc/common.md:27
$15 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$16 = true
(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at tm-constrs.h:10
$17 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$18 = true
(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at
/home/meissner/fsf-src/work036/gcc/common.md:27
$19 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$20 = true
(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at tm-constrs.h:10
$21 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$22 = true
(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at
/home/meissner/fsf-src/work036/gcc/common.md:27
$23 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$24 = true
(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at tm-constrs.h:10
$25 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$26 = true
(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at
/home/meissner/fsf-src/work036/gcc/common.md:27
$27 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$28 = true
(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at tm-constrs.h:10
$29 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$30 = true
(gdb) c
Continuing.

Breakpoint 2, satisfies_constraint_m (op=0x7ffff0de35e8) at
/home/meissner/fsf-src/work036/gcc/common.md:27
$31 = (rtx) 0x7ffff0de35e8
(mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182]) [1 x+0 S4 A32])
$32 = true
(gdb) c
Continuing.
[Inferior 1 (process 4757) exited normally]
(gdb) 


If we change rs6000_legitimate_address_p to return false if we have a prefixed
address and we are in asm, we get an insn not found error:

--- /home/meissner/tmp/gcc-tmp/TskwFJ_rs6000.c  2021-02-16 11:44:05.520201674
-0500
+++ gcc/config/rs6000/rs6000.c  2021-02-16 11:41:41.444740394 -0500
@@ -9532,7 +9532,7 @@ rs6000_legitimate_address_p (machine_mod

   /* Handle prefixed addresses (PC-relative or 34-bit offset).  */
   if (address_is_prefixed (x, mode, NON_PREFIXED_DEFAULT))
-    return 1;
+    return !recog_data.is_asm;

   /* Handle restricted vector d-form offsets in ISA 3.0.  */
   if (quad_offset_p)

$ file="foo02"; ./xgcc -B./ -O2 -mcpu=power10  -save-temps -c $file.c 
foo02.c:9:1: error: unrecognizable insn:
    9 | }
      | ^
(insn 7 5 12 2 (parallel [
            (set (reg:SI 3 3 [orig:118 a ] [118])
                (asm_operands:SI ("lwz%U0%X0 %0,%1") ("=r") 0 [
                        (mem/c:SI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182])
[1 x+0 S4 A32])
                    ]
                     [
                        (asm_input:SI ("m") foo02.c:7)
                    ]
                     [] foo02.c:7))
            (clobber (reg:SI 98 ca))
        ]) "foo02.c":7:3 -1
     (nil))
during RTL pass: reload
foo02.c:9:1: internal compiler error: in extract_constrain_insn, at
recog.c:2670
0x4d50db _fatal_insn(char const*, rtx_def const*, char const*, int, char
const*)
        /home/meissner/fsf-src/work036/gcc/rtl-error.c:108
0x4d50f7 _fatal_insn_not_found(rtx_def const*, char const*, int, char const*)
        /home/meissner/fsf-src/work036/gcc/rtl-error.c:116
0xb5907f extract_constrain_insn(rtx_insn*)
        /home/meissner/fsf-src/work036/gcc/recog.c:2670
0xa4d0a7 check_rtl
        /home/meissner/fsf-src/work036/gcc/lra.c:2087
0xa510ad lra(_IO_FILE*)
        /home/meissner/fsf-src/work036/gcc/lra.c:2505
0xa0bcf9 do_reload
        /home/meissner/fsf-src/work036/gcc/ira.c:5827
0xa0bcf9 execute
        /home/meissner/fsf-src/work036/gcc/ira.c:6013
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Reply via email to