<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW " title="NEW --- - Regression due to GMR changes in r242512" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24288&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=GZwWKqOs4-hljbMDCaFebMiHX31G5omJyqefhLVrGLs&s=AbndHRipMJkQIwEkaWnzW4zhDJnfr50kIMHtGOtBNRg&e=">24288</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Regression due to GMR changes in r242512
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Global Analyses
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>michael.m.kuperstein@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>We started seeing a lot of regressions in eembc. At least one of them (in
mp2decode) appears to reduce down to this:

@ptr = internal unnamed_addr global i8* getelementptr inbounds ([4096 x i8],
[4096 x i8]* @arr, i32 0, i32 0), align 4
@arr = internal global [4096 x i8] zeroinitializer, align 1

define i8* @foo(i32 %k, i32 %incr, i8* %p) {
entry:
  %start = icmp sgt i32 %k, 0
  br i1 %start, label %for.body, label %for.end

for.body:
  %i = phi i32 [ %next, %for.body ], [ 0, %entry ]
  %mul= mul nsw i32 %i, %incr
  %readptr = getelementptr inbounds i8, i8* %p, i32 %mul
  %val = load i8, i8* %readptr, align 1
  %writeptr = load i8*, i8** @ptr
  %newptr = getelementptr inbounds i8, i8* %writeptr
  store i8* %newptr, i8** @ptr, align 4
  store i8 %val, i8* %writeptr, align 1
  %cmpptr = load i8*, i8** @ptr
  %cmp = icmp eq i8* %cmpptr, getelementptr inbounds ([4096 x i8], [4096 x i8]*
@arr, i32 1, i32 0)
  %next = add i32 %i, 1
  br i1 %cmp, label %for.body, label %for.end

for.end:
  %ret = load i8*, i8** @ptr
  ret i8* %ret
}

The problem is that @ptr ends up in the same alias-set as the pointers based on
%p, messing up GVN:

opt -S C:\temp\mp2-reduced.ll -basicaa -globalsmodref-aa -print-alias-sets -gvn
-o -

Alias Set Tracker: 1 alias sets for 3 pointer values.
  AliasSet[0xdf3820, 3] may alias, Mod/Ref   Pointers: (i8* %readptr, 1), (i8**
@ptr, 8), (i8* %writeptr, 1)

; ModuleID = 'C:\temp\mp2-reduced.ll'

@ptr = internal unnamed_addr global i8* getelementptr inbounds ([4096 x i8],
[4096 x i8]* @arr, i32 0, i32 0), align 4
@arr = internal global [4096 x i8] zeroinitializer, align 1

define i8* @foo(i32 %k, i32 %incr, i8* %p) {
entry:
  %start = icmp sgt i32 %k, 0
  br i1 %start, label %entry.for.body_crit_edge, label %entry.for.end_crit_edge

entry.for.end_crit_edge:                          ; preds = %entry
  %ret.pre = load i8*, i8** @ptr
  br label %for.end

entry.for.body_crit_edge:                         ; preds = %entry
  %writeptr.pre = load i8*, i8** @ptr
  br label %for.body

for.body:                                         ; preds =
%entry.for.body_crit_edge, %for.body
  %writeptr = phi i8* [ getelementptr inbounds ([4096 x i8], [4096 x i8]* @arr,
i32 1, i32 0), %for.body ], [ %writeptr.pre, %entry.for.body_crit_edge ]
  %i = phi i32 [ %next, %for.body ], [ 0, %entry.for.body_crit_edge ]
  %mul = mul nsw i32 %i, %incr
  %readptr = getelementptr inbounds i8, i8* %p, i32 %mul
  %val = load i8, i8* %readptr, align 1
  store i8* %writeptr, i8** @ptr, align 4
  store i8 %val, i8* %writeptr, align 1
  %cmpptr = load i8*, i8** @ptr
  %cmp = icmp eq i8* %cmpptr, getelementptr inbounds ([4096 x i8], [4096 x i8]*
@arr, i32 1, i32 0)
  %next = add i32 %i, 1
  br i1 %cmp, label %for.body, label %for.end

for.end:                                          ; preds =
%entry.for.end_crit_edge, %for.body
  %ret = phi i8* [ %ret.pre, %entry.for.end_crit_edge ], [ %cmpptr, %for.body ]
  ret i8* %ret
}

But with -enable-unsafe-globalsmodref-alias-results:
Alias Set Tracker: 2 alias sets for 3 pointer values.
  AliasSet[0xcf9580, 2] may alias, Mod/Ref   Pointers: (i8* %readptr, 1), (i8*
%writeptr, 1)
  AliasSet[0xcf9620, 1] must alias, Mod/Ref   Pointers: (i8** @ptr, 8)

; ModuleID = 'C:\temp\mp2-reduced.ll'

@ptr = internal unnamed_addr global i8* getelementptr inbounds ([4096 x i8],
[4096 x i8]* @arr, i32 0, i32 0), align 4
@arr = internal global [4096 x i8] zeroinitializer, align 1

define i8* @foo(i32 %k, i32 %incr, i8* %p) {
entry:
  %start = icmp sgt i32 %k, 0
  br i1 %start, label %entry.for.body_crit_edge, label %entry.for.end_crit_edge

entry.for.end_crit_edge:                          ; preds = %entry
  %ret.pre = load i8*, i8** @ptr
  br label %for.end

entry.for.body_crit_edge:                         ; preds = %entry
  %writeptr.pre = load i8*, i8** @ptr
  br label %for.body

for.body:                                         ; preds =
%entry.for.body_crit_edge, %for.body
  %writeptr = phi i8* [ getelementptr inbounds ([4096 x i8], [4096 x i8]* @arr,
i32 1, i32 0), %for.body ], [ %writeptr.pre, %entry.for.body_crit_edge ]
  %i = phi i32 [ %next, %for.body ], [ 0, %entry.for.body_crit_edge ]
  %mul = mul nsw i32 %i, %incr
  %readptr = getelementptr inbounds i8, i8* %p, i32 %mul
  %val = load i8, i8* %readptr, align 1
  store i8* %writeptr, i8** @ptr, align 4
  store i8 %val, i8* %writeptr, align 1
  %cmp = icmp eq i8* %writeptr, getelementptr inbounds ([4096 x i8], [4096 x
i8]* @arr, i32 1, i32 0)
  %next = add i32 %i, 1
  br i1 %cmp, label %for.body, label %for.end

for.end:                                          ; preds =
%entry.for.end_crit_edge, %for.body
  %ret = phi i8* [ %ret.pre, %entry.for.end_crit_edge ], [ %writeptr, %for.body
]
  ret i8* %ret
}</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>