/* (&a + b) !=/== (&a[1] + c) -> (&a[0] - &a[1]) + b !=/== c */
(for neeq (ne eq)
(simplify
- (neeq:c ADDR_EXPR@0 (pointer_plus ADDR_EXPR@2 @3))
+ (neeq:c ADDR_EXPR@0 (pointer_plus @2 @3))
(with { poly_int64 diff; tree inner_type = TREE_TYPE (@3);}
(if (ptr_difference_const (@0, @2, &diff))
(neeq { build_int_cst_type (inner_type, diff); } @3))))
return b - a;
}
+int bar (struct b *x)
+{
+ int *a = x->data;
+ int *b = ((int*)x) + 4;
+ if (a != b)
+ return 1;
+ return 0;
+}
+
+int baz (struct b *x)
+{
+ int *a = x->data;
+ int *b = ((int*)x) + 4;
+ return (a != b);
+}
+
/* { dg-final { scan-tree-dump "return 4;" "ccp1" } } */
+/* { dg-final { scan-tree-dump-times "return 1;" 2 "ccp1" } } */
static tree
ccp_fold (gimple *stmt)
{
- location_t loc = gimple_location (stmt);
switch (gimple_code (stmt))
{
- case GIMPLE_COND:
- {
- /* Handle comparison operators that can appear in GIMPLE form. */
- tree op0 = valueize_op (gimple_cond_lhs (stmt));
- tree op1 = valueize_op (gimple_cond_rhs (stmt));
- enum tree_code code = gimple_cond_code (stmt);
- return fold_binary_loc (loc, code, boolean_type_node, op0, op1);
- }
-
case GIMPLE_SWITCH:
{
/* Return the constant switch index. */
return valueize_op (gimple_switch_index (as_a <gswitch *> (stmt)));
}
+ case GIMPLE_COND:
case GIMPLE_ASSIGN:
case GIMPLE_CALL:
return gimple_fold_stmt_to_constant_1 (stmt,