[llvm-bugs] [Bug 39119] New: Null check elimination when callsite args are nonnull
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Sep 28 12:39:32 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=39119
Bug ID: 39119
Summary: Null check elimination when callsite args are nonnull
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: david.bolvansky at gmail.com
CC: llvm-bugs at lists.llvm.org
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180928/b84bac66/attachment.html>
More information about the llvm-bugs
mailing list