<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - Bug in pass 'ipsccp' on function attribute 'argmemonly'."
   href="https://bugs.llvm.org/show_bug.cgi?id=46717">46717</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Bug in pass 'ipsccp' on function attribute 'argmemonly'.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

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

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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>opt
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>fangqingdu@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When pass 'ipsccp' replaces arguments with global variables, it forgets to
remove the function's 'argmemonly' attribute. Which may cause wrong behavior,
just like following test case(from Alexandre Isoard) shows:

********************************************************
; RUN: opt -ipsccp -deadargelim -licm -O2 -S < %s

@g = internal global i32 0

; Function Attrs: argmemonly
define internal void @foo(i32* nonnull dereferenceable(4) %arg, i32 %val) #0 {
entry:
  store i32 %val, i32* %arg
  ret void
}

define i32 @bar(i32 %n) {
entry:
  store i32 1, i32* @g
  br label %loop

loop:                                              ; preds = %bb1, %bb
  %i = phi i32 [ %i.inc, %loop ], [ 0, %entry ]
  %g.val = load i32, i32* @g
  %g.inc = add nuw i32 %g.val, 1
  tail call void @foo(i32* @g, i32 %g.inc)
  %i.inc = add nuw i32 %i, 1
  %cond = icmp eq i32 %i.inc, %n
  br i1 %cond, label %exit, label %loop

exit:                                              ; preds = %bb1
  ret i32 %g.val
}

declare void @llvm.assume(i1)

attributes #0 = { argmemonly }
********************************************************

Before 'ipsccp', function '@foo' is marked with 'argmemonly' attribute. But
after the argument '%arg' is replaced with '@g' by pass 'ipsccp', attribute
'argmemonly' is left there. And due to the 'argmemonly' attribute, pass 'licm'
will think the value of global variable '@g' is not changed (but it is
changed), then hoist the load of the '@g' outside the loop. And cause function
'@bar' return wrong value '1'. But the correct return value should be '%n'.</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>