https://gcc.gnu.org/g:fbdabd5f9a27c80a19767918adaa1ee968cf4adf
commit r17-3169-gfbdabd5f9a27c80a19767918adaa1ee968cf4adf Author: Andrea Pinski <[email protected]> Date: Sat Aug 8 11:03:55 2026 -0700 gimplefe: Add support for REF_REVERSE_STORAGE_ORDER on mem While fixing PR 126729 and PR 126570, I found it was hard to figure out if REF_REVERSE_STORAGE_ORDER was set on a MEM_REF. Even for the gimple fe was able to set it. This adds support to the gimple fe and also outputs REF_REVERSE_STORAGE_ORDER for MEM_REF in gimple mode. Bootstrapped and tested on x84_64-linux-gnu. gcc/c/ChangeLog: * gimple-parser.cc (c_parser_gimple_postfix_expression): Allow for an optional `, 1/0` in front of the cb pair for MEM_REF. gcc/ChangeLog: * tree-pretty-print.cc (dump_mem_ref): Dump REF_REVERSE_STORAGE_ORDER if it was set. gcc/testsuite/ChangeLog: * gcc.dg/gimplefe-59.c: New test. Signed-off-by: Andrea Pinski <[email protected]> Diff: --- gcc/c/gimple-parser.cc | 34 ++++++++++++++++++++++++++++++++-- gcc/testsuite/gcc.dg/gimplefe-59.c | 16 ++++++++++++++++ gcc/tree-pretty-print.cc | 6 ++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/gcc/c/gimple-parser.cc b/gcc/c/gimple-parser.cc index 0fcb9ead83d1..59cb29f420c7 100644 --- a/gcc/c/gimple-parser.cc +++ b/gcc/c/gimple-parser.cc @@ -1530,6 +1530,7 @@ c_parser_gimple_postfix_expression (gimple_parser &parser) /* __MEM '<' type-name [ ',' number ] '>' '(' [ '(' type-name ')' ] unary-expression [ '+' number ] + [ ',' number ] [ ',' number ':' number ] ')' */ location_t loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); @@ -1542,6 +1543,8 @@ c_parser_gimple_postfix_expression (gimple_parser &parser) index2.value = NULL_TREE; unsigned short clique = 0; unsigned short base = 0; + bool reverse_order = false; + struct c_expr ro; if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { tree alias_type = NULL_TREE; @@ -1626,10 +1629,29 @@ c_parser_gimple_postfix_expression (gimple_parser &parser) if (c_parser_next_token_is (parser, CPP_COMMA)) { struct c_expr cl, ba; + bool has_clb = true; c_parser_consume_token (parser); cl = c_parser_gimple_postfix_expression (parser); - if (c_parser_require (parser, - CPP_COLON, "expected %<:%>")) + if (!c_parser_next_token_is (parser, CPP_COLON)) + { + ro = cl; + unsigned HOST_WIDE_INT tmp = 0; + if (!tree_fits_uhwi_p (ro.value) + || (tmp = tree_to_uhwi (ro.value)) > 1) + error_at (ro.get_start (), + "invalid reverse order value"); + reverse_order = tmp; + has_clb = false; + if (c_parser_next_token_is (parser, CPP_COMMA)) + { + c_parser_consume_token (parser); + cl = c_parser_gimple_postfix_expression (parser); + has_clb = true; + } + } + if (has_clb + && c_parser_require (parser, + CPP_COLON, "expected %<:%>")) { ba = c_parser_gimple_postfix_expression (parser); if (!tree_fits_uhwi_p (cl.value) @@ -1665,6 +1687,14 @@ c_parser_gimple_postfix_expression (gimple_parser &parser) MR_DEPENDENCE_CLIQUE (expr.value) = clique; MR_DEPENDENCE_BASE (expr.value) = base; } + if (reverse_order) + { + if (TREE_CODE (expr.value) == MEM_REF) + REF_REVERSE_STORAGE_ORDER (expr.value) = reverse_order; + else + error_at (ro.get_start (), + "target mem ref cannot have reverse order"); + } break; } else if (strcmp (IDENTIFIER_POINTER (id), "__VIEW_CONVERT") == 0) diff --git a/gcc/testsuite/gcc.dg/gimplefe-59.c b/gcc/testsuite/gcc.dg/gimplefe-59.c new file mode 100644 index 000000000000..296c088a2a06 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-59.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ + +/* test REF_REVERSE_STORAGE_ORDER parsing of gimple fe. */ + +int __GIMPLE (ssa,guessed_local(1073741824)) +f2 (void * a, bool b, bool bb) +{ + int _1; + + __BB(2,guessed_local(1073741824)): + _1 = __MEM <int> (a_5(D), 1); + return _1; + +} + diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc index bd60e5c15c19..316945c00ede 100644 --- a/gcc/tree-pretty-print.cc +++ b/gcc/tree-pretty-print.cc @@ -2075,6 +2075,12 @@ dump_mem_ref (pretty_printer *pp, tree node, int spc, dump_flags_t flags) spc, flags | TDF_SLIM, false); } } + if (TREE_CODE (node) == MEM_REF + && REF_REVERSE_STORAGE_ORDER (node)) + { + pp_string (pp, ", "); + pp_decimal_int (pp, REF_REVERSE_STORAGE_ORDER (node)); + } if (MR_DEPENDENCE_CLIQUE (node) != 0) { pp_string (pp, ", ");
