<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 - Null check elimination when callsite args are nonnull"
   href="https://bugs.llvm.org/show_bug.cgi?id=39119">39119</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Null check elimination when callsite args are nonnull
          </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>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>david.bolvansky@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>int foo(char *d, char *s) {
    int res = strncmp(d, s, 10);
    if (!s)
        abort();
    return res;
}

Current -O3 IR:
define dso_local i32 @foo(i8* nocapture readonly %d, i8* readonly %s)
local_unnamed_addr #0 {
entry:
  %tobool = icmp eq i8* %s, null
  br i1 %tobool, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  tail call void @abort() #3
  unreachable

if.end:                                           ; preds = %entry
  %call = tail call i32 @strncmp(i8* %d, i8* nonnull %s, i64 10) #4
  ret i32 %call
}

We somehow miss logic to remove "top level null check", if all uses of %s are
in "nonnull" places

---------------------------------------------

For similar code:
int foo(char *d, char *s) {
    int res = strncmp(d, s, 10);
    if (!s)
        abort();
    if (!d)
        exit(1);
    return res;
}

We get:
define dso_local i32 @foo(i8* readonly %d, i8* readonly %s) local_unnamed_addr
#0 {
entry:
  %call = tail call i32 @strncmp(i8* %d, i8* %s, i64 10) #3
  %tobool = icmp eq i8* %s, null
  br i1 %tobool, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  tail call void @abort() #4
  unreachable

if.end:                                           ; preds = %entry
  %tobool1 = icmp eq i8* %d, null
  br i1 %tobool1, label %if.then2, label %if.end3

if.then2:                                         ; preds = %if.end
  tail call void @exit(i32 1) #4
  unreachable

if.end3:                                          ; preds = %if.end
  ret i32 %call
}

But if I change
%call = tail call i32 @strncmp(i8* %d, i8* %s, i64 10) #3
to 
%call = tail call i32 @strncmp(i8* nonnull %d, i8* nonnull %s, i64 10) #3

Ran:
opt -O3 -enable-nonnull-arg-prop aa.ll -S

No eliminations :/ We need to propagate nonnull info more.</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>