[llvm-bugs] [Bug 24920] New: SCEV Expander fails to reuse existing values
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Sep 23 20:34:32 PDT 2015
https://llvm.org/bugs/show_bug.cgi?id=24920
Bug ID: 24920
Summary: SCEV Expander fails to reuse existing values
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: michael.v.zolotukhin at gmail.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Currently SCEV expander only reuses existing values if they're exactly like the
one it tries to expand. However, it should be able to use similar values (not
exactly the same) to generate more optimal code.
Below is the example:
------------------
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
; Function Attrs: noinline nounwind ssp uwtable
define i8* @foo(i32 %y, i8* noalias %src, i8* noalias %dst) {
entry:
%cmp = icmp slt i32 %y, 4096
%sub = add nsw i32 %y, -1
%tripcount = select i1 %cmp, i32 %sub, i32 4095
%loop.entry.cond = icmp sgt i32 %tripcount, 0
br i1 %loop.entry.cond, label %loop.ph, label %loop.exit
loop.ph: ; preds = %entry
br label %loop.body
loop.body: ; preds = %loop.body,
%loop.ph
%iv = phi i32 [ 0, %loop.ph ], [ %iv.next, %loop.body ]
%src.iv = phi i8* [ %src, %loop.ph ], [ %src.iv.next, %loop.body ]
%dst.iv = phi i8* [ %dst, %loop.ph ], [ %dst.iv.next, %loop.body ]
%tmp = load i8, i8* %src.iv, align 1
store i8 %tmp, i8* %dst.iv, align 1
%src.iv.next = getelementptr inbounds i8, i8* %src.iv, i64 1
%dst.iv.next = getelementptr inbounds i8, i8* %dst.iv, i64 1
%iv.next = add nsw i32 %iv, 1
%loop.cond = icmp slt i32 %iv.next, %tripcount
br i1 %loop.cond, label %loop.body, label %loop.exit
loop.exit: ; preds = %loop.exit, %entry
%src.iv.lcssa = phi i8* [ %src.iv.next, %loop.body ], [ %src, %entry ]
ret i8* undef
}
!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}
!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 1, !"PIC Level", i32 2}
!2 = !{!"clang version 3.8.0 (trunk 247767) (llvm/trunk 247769)"}
------------------
In this test it fails to rewrite exit value for %src, as its SCEV value
contains smax, which is considered expensive. However, it doesn't need to
generate code for smax, because such code already exists and the result is in
%tripcount value.
This bug was revealed in this review: http://reviews.llvm.org/D12765
--
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/20150924/a39d0050/attachment-0001.html>
More information about the llvm-bugs
mailing list