Bug 50419 - Casts to restrict pointers have no effect
Summary: Casts to restrict pointers have no effect
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: alias, missed-optimization
Depends on:
Blocks: restrict
  Show dependency treegraph
 
Reported: 2011-09-15 14:14 UTC by Michael Matz
Modified: 2022-12-26 06:39 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-08-18 00:00:00


Attachments
(untested) patch (505 bytes, patch)
2011-09-15 14:16 UTC, Michael Matz
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Matz 2011-09-15 14:14:07 UTC
% cat predcom-fail.c
#define INFTY       987654321
#define Ra /*__restrict*/
#define Rv __restrict
void
P7Viterbi(int * Ra _dc, int * Ra _mc, int * Ra _tpdd, int * Ra _tpmd, int M)
{
  int   i,k;
  int   sc;
  int * Rv dc = _dc;
  int * Rv mc = _mc;
  int * Rv tpdd = _tpdd;
  int * Rv tpmd = _tpmd;

  dc[0] = -INFTY;

  for (k = 1; k < M; k++) {
    dc[k] = dc[k-1] + tpdd[k-1];
    if ((sc = mc[k-1] + tpmd[k-1]) > dc[k]) dc[k] = sc;
    if (dc[k] < -INFTY) dc[k] = -INFTY;
  }
}

./cc1 -Ofast predcom-fail.c should be able to predcom the loop.  It doesn't
because it doesn't see that the (first) dc[] write doesn't conflict with the
mc/tpmd[] reads.  It should be able to see that because all the int pointers
are created with new restrict sets.  If you defined Ra as also __restrict
(making the arguments already restrict qualified) you get the transformation.

The problem is an interaction between creating the datarefs and the
disambiguator.  The data-ref base objects contain the casted inputs:

#(Data Ref:
#  bb: 4
#  stmt: D.2741_19 = *D.2740_18;
#  ref: *D.2740_18;
#  base_object: *(int * restrict) _dc_2(D);
#  Access function 0: {0B, +, 4}_1
#)
vs
#(Data Ref:
#  bb: 4
#  stmt: D.2743_24 = *D.2742_23;
#  ref: *D.2742_23;
#  base_object: *(int * restrict) _tpdd_6(D);
#  Access function 0: {0B, +, 4}_1
#)

The disambiguator used is ptr_derefs_may_alias_p on those two (casted)
pointers.  But the first thing it does is to remove all conversions.
Remembering the original type wouldn't help as we need to look into the
points-to info of the restrict qualified object (i.e. the LHS of that
conversion).

Hence when creating the data-ref we shouldn't look through such casts, that
introduce useful information.  I have a patch.
Comment 1 Michael Matz 2011-09-15 14:16:54 UTC
Created attachment 25293 [details]
(untested) patch

Potential fix for this.  As yet untested.
Comment 2 Michael Matz 2011-10-12 15:09:53 UTC
Meeh, since the fix for PR49279 we don't retain the casts to restrict anymore,
making the testcase not work even with the fix.
Comment 3 Richard Biener 2016-08-18 12:34:10 UTC
Note that "cast-restrict" support has been removed and thus it is now expected that only the restrict argument case is handled.

But - confirmed.  Nothing to do with dataref analysis though.