View | Details | Return to bug 58145 | Differences between
and this patch

Collapse All | Expand All

(-)gcc/tree-sra.c.jj (-2 / +10 lines)
Lines 1466-1474 build_ref_for_offset (location_t loc, tr Link Here
1466
{
1466
{
1467
  tree prev_base = base;
1467
  tree prev_base = base;
1468
  tree off;
1468
  tree off;
1469
  tree mem_ref;
1469
  HOST_WIDE_INT base_offset;
1470
  HOST_WIDE_INT base_offset;
1470
  unsigned HOST_WIDE_INT misalign;
1471
  unsigned HOST_WIDE_INT misalign;
1471
  unsigned int align;
1472
  unsigned int align;
1473
  bool is_volatile = TREE_THIS_VOLATILE (TREE_TYPE (base));
1472
1474
1473
  gcc_checking_assert (offset % BITS_PER_UNIT == 0);
1475
  gcc_checking_assert (offset % BITS_PER_UNIT == 0);
1474
  get_object_alignment_1 (base, &align, &misalign);
1476
  get_object_alignment_1 (base, &align, &misalign);
Lines 1515-1522 build_ref_for_offset (location_t loc, tr Link Here
1515
    align = (misalign & -misalign);
1517
    align = (misalign & -misalign);
1516
  if (align < TYPE_ALIGN (exp_type))
1518
  if (align < TYPE_ALIGN (exp_type))
1517
    exp_type = build_aligned_type (exp_type, align);
1519
    exp_type = build_aligned_type (exp_type, align);
1518
1520
  if (is_volatile && !TREE_THIS_VOLATILE (exp_type))
1519
  return fold_build2_loc (loc, MEM_REF, exp_type, base, off);
1521
    exp_type = build_qualified_type (exp_type, TYPE_QUALS (exp_type)
1522
					       | TYPE_QUAL_VOLATILE);
1523
1524
  mem_ref = fold_build2_loc (loc, MEM_REF, exp_type, base, off);
1525
  if (TREE_THIS_VOLATILE (exp_type))
1526
    TREE_THIS_VOLATILE (mem_ref) = 1;
1527
  return mem_ref;
1520
}
1528
}
1521
1529
1522
/* Construct a memory reference to a part of an aggregate BASE at the given
1530
/* Construct a memory reference to a part of an aggregate BASE at the given
(-)gcc/testsuite/gcc.dg/pr58145-1.c.jj (+37 lines)
Line 0 Link Here
1
/* PR tree-optimization/58145 */
2
/* { dg-do compile { target { int32plus } } } */
3
/* { dg-options "-O2 -fdump-tree-optimized" } */
4
5
struct S { unsigned int data : 32; };
6
struct T { unsigned int data; };
7
volatile struct S s2;
8
9
void
10
f1 (int val)
11
{
12
  struct S s = { .data = val };
13
  *(volatile struct S *) 0x880000UL = s;
14
}
15
16
void
17
f2 (int val)
18
{
19
  struct T t = { .data = val };
20
  *(volatile struct T *) 0x880000UL = t;
21
}
22
23
void
24
f3 (int val)
25
{
26
  *(volatile unsigned int *) 0x880000UL = val;
27
}
28
29
void
30
f4 (int val)
31
{
32
  struct S s = { .data = val };
33
  s2 = s;
34
}
35
36
/* { dg-final { scan-tree-dump-times " ={v} " 4 "optimized" } } */
37
/* { dg-final { cleanup-tree-dump "optimized" } } */
(-)gcc/testsuite/gcc.dg/pr58145-2.c.jj (+51 lines)
Line 0 Link Here
1
/* PR tree-optimization/58145 */
2
/* { dg-do compile { target { int32plus } } } */
3
/* { dg-options "-O2 -fdump-tree-optimized" } */
4
5
struct S { unsigned int data : 32; };
6
struct T { unsigned int data; };
7
volatile struct S s2;
8
9
static inline void
10
f1 (int val)
11
{
12
  struct S s = { .data = val };
13
  *(volatile struct S *) 0x880000UL = s;
14
}
15
16
static inline void
17
f2 (int val)
18
{
19
  struct T t = { .data = val };
20
  *(volatile struct T *) 0x880000UL = t;
21
}
22
23
static inline void
24
f3 (int val)
25
{
26
  *(volatile unsigned int *) 0x880000UL = val;
27
}
28
29
static inline void
30
f4 (int val)
31
{
32
  struct S s = { .data = val };
33
  s2 = s;
34
}
35
36
void
37
f5 (void)
38
{
39
  int i;
40
  for (i = 0; i < 100; i++)
41
    f1 (0);
42
  for (i = 0; i < 100; i++)
43
    f2 (0);
44
  for (i = 0; i < 100; i++)
45
    f3 (0);
46
  for (i = 0; i < 100; i++)
47
    f4 (0);
48
}
49
50
/* { dg-final { scan-tree-dump-times " ={v} " 4 "optimized" } } */
51
/* { dg-final { cleanup-tree-dump "optimized" } } */

Return to bug 58145