This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

One extra reference folding case


Hi,
we tend to break testcase (derrived from testsuite):

int x[2] = { 1, 2 };

#ifdef __OPTIMIZE__
static inline void __attribute__((__always_inline__))
insn1 (int x)
{
  asm volatile ("" :: "n" (x), "i" (x));
}

static inline void __attribute__((__always_inline__))
insn2 (const void *x)
{
  asm volatile ("" :: "s" (x), "i" (x));
}
#endif

void
foo (void)
{
#ifdef __OPTIMIZE__
  insn2 (&x[1]);
#if 0
  insn2 ("string");
#endif
#endif
}

What goes wrong is that testcase insist on &x[1] being constant, that it is.
However we decompose it as (void *)&x + 4 that we are never able to synthetize back
to the (void *)&x[4]. This patch adds appropriate folder to gimplifier.

Bootstrapped/regtested i686-linux, OK?
Honza

	* gimplify.c (gimplify_expr): Fold (void *)&a + 4.
Index: gimplify.c
===================================================================
*** gimplify.c	(revision 124378)
--- gimplify.c	(working copy)
*************** gimplify_expr (tree *expr_p, tree *pre_p
*** 5881,5887 ****
  	     {
                 *expr_p = build_fold_addr_expr_with_type (tmp,
  							 TREE_TYPE (*expr_p));
! 		break;
  	     }
            /* FALLTHRU */
  	default:
--- 5881,5902 ----
  	     {
                 *expr_p = build_fold_addr_expr_with_type (tmp,
  							 TREE_TYPE (*expr_p));
! 	       break;
! 	     }
! 	  /* Convert (void *)&a + 4 into (void *)&a[1].  */
! 	  if (POINTER_TYPE_P (TREE_TYPE (*expr_p))
! 	      && TREE_CODE (TREE_OPERAND (*expr_p, 0)) == NOP_EXPR
! 	      && TREE_CODE (TREE_OPERAND (*expr_p, 1)) == INTEGER_CST
! 	      && (tmp = maybe_fold_offset_to_reference
! 			 (TREE_OPERAND (TREE_OPERAND (*expr_p, 0), 0),
! 			  TREE_OPERAND (*expr_p, 1),
! 		   	  TREE_TYPE (TREE_TYPE
! 				  (TREE_OPERAND (TREE_OPERAND (*expr_p, 0),
! 						 0))))))
! 	     {
!                tmp = build_fold_addr_expr (tmp);
!                *expr_p = fold_convert (TREE_TYPE (*expr_p), tmp);
! 	       break;
  	     }
            /* FALLTHRU */
  	default:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]