[PATCH] D81026: Inline Cost improvement - GetElementPtr with constant operands
Kirill Naumov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 2 12:38:01 PDT 2020
knaumov created this revision.
knaumov added reviewers: apilipenko, davidxl, mtrofin.
Herald added subscribers: llvm-commits, haicheng, hiraditya, eraman.
Herald added a project: LLVM.
Currently, InlineCost doesn't simplify GetElementPtr with constant operands. In this patch, we are introducing this functionality.
The improvement is built on a similar lambda-structure as the other simplification of instructions with constant operands.
https://reviews.llvm.org/D81026
Files:
llvm/lib/Analysis/InlineCost.cpp
llvm/test/Transforms/Inline/gep_from_constant.ll
Index: llvm/test/Transforms/Inline/gep_from_constant.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Inline/gep_from_constant.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -passes="print<inline-cost>" 2>&1 | FileCheck %s
+
+; CHECK-LABEL: @foo
+; CHECK: cost before = {{.*}}, cost after = {{.*}}, threshold before = {{.*}}, threshold after = {{.*}}, cost delta = {{.*}}, simplified to i8 addrspace(1)** getelementptr (i8 addrspace(1)*, i8 addrspace(1)** inttoptr (i64 754974720 to i8 addrspace(1)**), i64 5)
+
+define i8 addrspace(1)** @foo(i64 %0) {
+ %2 = inttoptr i64 754974720 to i8 addrspace(1)**
+ %3 = getelementptr i8 addrspace(1)*, i8 addrspace(1)** %2, i64 %0
+ ret i8 addrspace(1)** %3
+}
+
+define i8 addrspace(1)** @main() {
+ %1 = call i8 addrspace(1)** @foo(i64 5)
+ ret i8 addrspace(1)** %1
+}
Index: llvm/lib/Analysis/InlineCost.cpp
===================================================================
--- llvm/lib/Analysis/InlineCost.cpp
+++ llvm/lib/Analysis/InlineCost.cpp
@@ -1003,6 +1003,15 @@
return true;
};
+ if (simplifyInstruction(I, [&](SmallVectorImpl<Constant *> &COps) {
+ SmallVector<Constant *, 2> Indices;
+ for (unsigned int index = 1 ; index < COps.size() ; ++index)
+ Indices.push_back(COps[index]);
+ return ConstantExpr::getGetElementPtr(I.getSourceElementType(), COps[0],
+ Indices, I.isInBounds());
+ }))
+ return true;
+
if ((I.isInBounds() && canFoldInboundsGEP(I)) || IsGEPOffsetConstant(I)) {
if (SROAArg)
SROAArgValues[&I] = SROAArg;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81026.267955.patch
Type: text/x-patch
Size: 1634 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200602/da922897/attachment.bin>
More information about the llvm-commits
mailing list