[llvm-bugs] [Bug 41553] New: a loop with a pointer increment is folded into a form that it fails to optimize further
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Apr 21 17:03:17 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=41553
Bug ID: 41553
Summary: a loop with a pointer increment is folded into a form
that it fails to optimize further
Product: new-bugs
Version: trunk
Hardware: PC
OS: All
Status: NEW
Keywords: code-quality
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: nok.raven at gmail.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org
The foo should be equivalent to bar when sizeof(n) < sizeof(p)
int* foo(int* p, unsigned n)
{
for (unsigned i = 0; i < n; ++i)
++p;
return p;
}
int* bar(int* p, unsigned n)
{
p += n;
return p;
}
Produced IR:
define i32* @foo(i32* readnone, i32) {
%3 = icmp eq i32 %1, 0
%4 = add i32 %1, -1
%5 = zext i32 %4 to i64
%6 = add nuw nsw i64 %5, 1
%7 = getelementptr i32, i32* %0, i64 %6
%8 = select i1 %3, i32* %0, i32* %7
ret i32* %8
}
define i32* @bar(i32* readnone, i32) {
%3 = zext i32 %1 to i64
%4 = getelementptr inbounds i32, i32* %0, i64 %3
ret i32* %4
}
The branch looks strange, but even if I rewrite it:
Pre: C0 > 0
%a = add i32 C0, -1
%b = zext i32 %a to i64
%r = add nuw nsw i64 %b, 1
=>
%r = zext i32 C0 to i64
https://rise4fun.com/Alive/wiV
define i32* @foo2(i32* readnone, i32) {
%3 = icmp eq i32 %1, 0
%4 = zext i32 %1 to i64
%5 = getelementptr i32, i32* %0, i64 %4
%6 = select i1 %3, i32* %0, i32* %5
ret i32* %6
}
It is not optimized further.
--
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/20190422/f2e98b31/attachment.html>
More information about the llvm-bugs
mailing list