[llvm-bugs] [Bug 33642] New: [InlineCost] CallAnalyzer::visitGetElementPtr can return true for GEPS which are not cost-free
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Jun 29 07:14:37 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=33642
Bug ID: 33642
Summary: [InlineCost] CallAnalyzer::visitGetElementPtr can
return true for GEPS which are not cost-free
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Interprocedural Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: eastig at yandex.ru
CC: llvm-bugs at lists.llvm.org
In the following IR produced from the code of a simple memcopy function GEPs
are not free:
while.cond: ; preds = %while.body, %entry
%dest.addr.0 = phi i8* [ %dest, %entry ], [ %incdec.ptr1, %while.body ]
%src.addr.0 = phi i8* [ %src, %entry ], [ %incdec.ptr, %while.body ]
%tobool = icmp eq i32 %size.addr.0, 0
br i1 %tobool, label %while.end, label %while.body
while.body: ; preds = %while.cond
%dec = add nsw i32 %size.addr.0, -1
%incdec.ptr = getelementptr inbounds i8, i8* %src.addr.0, i32 1
%0 = load i8, i8* %src.addr.0, align 1, !tbaa !12
%incdec.ptr1 = getelementptr inbounds i8, i8* %dest.addr.0, i32 1
store i8 %0, i8* %dest.addr.0, align 1, !tbaa !12
br label %while.cond
while.end: ; preds = %while.cond
For x86 and ARM they are lowered into ADD instructions.
The analysis of GEPs is done in CallAnalyzer::visitGetElementPtr.
There is the code:
if (IsGEPOffsetConstant(I)) {
if (SROACandidate)
SROAArgValues[&I] = SROAArg;
// Constant GEPs are modeled as free.
return true;
}
For all GEPs with constant offsets true is returned. The example above shows
when GEPs with constant offsets are not free. So we need to call isGEPFree to
check if GEP is actually free of cost.
Note: there is a patch (https://reviews.llvm.org/D33685) of isGEPFree to use
TTI::getUserCost instead of TTI::getGEPCost. TTI::getUserCost will catch the
cases above.
--
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/20170629/fae13c01/attachment.html>
More information about the llvm-bugs
mailing list