This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fixes for PR66178
- From: Jeff Law <law at redhat dot com>
- To: Bernd Schmidt <bschmidt at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 20 Jan 2016 20:12:59 -0700
- Subject: Re: Fixes for PR66178
- Authentication-results: sourceware.org; auth=none
- References: <569F9214 dot 8060007 at t-online dot de> <569F98C8 dot 4090907 at redhat dot com>
On 01/20/2016 07:25 AM, Bernd Schmidt wrote:
PR66178 has some testcases where we construct expressions involving
additions and subtractions of label addresses, and we crash when trying
to expand these. There are two different issues here, shown by various
testcases in the PR:
* expand_expr_real_2 can drop EXPAND_INITIALIZER and then go into
a path where it wants to gen_reg_rtx.
* simplify-rtx can turn subtractions into NOT operations in some
cases. That seems inadvisable for symbolic expressions.
The following was bootstrapped and tested on x86_64-linux. Ok for all
branches?
PR middle-end/66178
* expr.c (expand_expr_real_2) [PLUS_EXPR, MINUS_EXPR]: Don't
drop EXPAND_INITIALIZER.
* rtl.h (contains_symbolic_reference_p): Declare.
* rtlanal.c (contains_symbolic_reference_p): New function.
* simplify-rtx.c (simplify_binary_operation_1): Don't turn
a subtraction into a NOT if symbolic constants are involved.
testsuite/
PR middle-end/66178
gcc.dg/torture/pr66178.c: New test.
pr66178.diff
Index: gcc/rtlanal.c
===================================================================
--- gcc/rtlanal.c (revision 232555)
+++ gcc/rtlanal.c (working copy)
@@ -6243,6 +6243,19 @@ contains_symbol_ref_p (const_rtx x)
return false;
}
+/* Return true if RTL X contains a SYMBOL_REF or LABEL_REF. */
+
+bool
+contains_symbolic_reference_p (const_rtx x)
+{
+ subrtx_iterator::array_type array;
+ FOR_EACH_SUBRTX (iter, array, x, ALL)
+ if (SYMBOL_REF_P (*iter) || GET_CODE (*iter) == LABEL_REF)
+ return true;
+
+ return false;
+}
+
I thought we already had a routine to do this. I thought we needed it
in varasm.c, but couldn't find it. Then I found contains_symbol_ref_p,
but obviously that's not good enough because you need LABEL_REFs too.
/* Return true if X contains a thread-local symbol. */
bool
Index: gcc/simplify-rtx.c
===================================================================
--- gcc/simplify-rtx.c (revision 232555)
+++ gcc/simplify-rtx.c (working copy)
@@ -2277,8 +2277,11 @@ simplify_binary_operation_1 (enum rtx_co
if (!HONOR_SIGNED_ZEROS (mode) && trueop0 == CONST0_RTX (mode))
return simplify_gen_unary (NEG, mode, op1, mode);
- /* (-1 - a) is ~a. */
- if (trueop0 == constm1_rtx)
+ /* (-1 - a) is ~a, unless the expression avoids symbolic constants,
+ in which case not retaining additions and subtractions could
+ cause invalid assembly to be produced. */
"avoids?" Somehow this isn't parsing well.
"unless the expression has symbolic constants" or something similar is
what I think you want.
OK with the comment fixed.
jeff