<div dir="ltr"><pre style="color:rgb(0,0,0)">This bot fails after the patch</pre><pre style="user-select: text; top: -99px;"><font color="#000000"><a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/4176/steps/check-msan%20in%20gcc%20build/logs/stdio">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/4176/steps/check-msan%20in%20gcc%20build/logs/stdio</a><br></font></pre><pre style="color:rgb(0,0,0)"><br></pre><pre style="color:rgb(0,0,0)">7 warnings generated.
clang-6.0: /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/include/llvm/Support/Casting.h:255: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = llvm::Operator; Y = const llvm::User; typename llvm::cast_retty<X, Y*>::ret_type = const llvm::Operator*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
#0 0x0000000001f90f1a llvm::sys::PrintStackTrace(llvm::raw_ostream&) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/Support/Unix/Signals.inc:402:0
#1 0x0000000001f8ed7e llvm::sys::RunSignalHandlers() /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/Support/Signals.cpp:50:0
#2 0x0000000001f8eef2 SignalHandler(int) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/Support/Unix/Signals.inc:242:0
#3 0x00007f835e2fc390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
#4 0x00007f835d288428 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x35428)
#5 0x00007f835d28a02a abort (/lib/x86_64-linux-gnu/libc.so.6+0x3702a)
#6 0x00007f835d280bd7 (/lib/x86_64-linux-gnu/libc.so.6+0x2dbd7)
#7 0x00007f835d280c82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
#8 0x0000000001352326 llvm::cast_retty<llvm::Operator, llvm::User const*>::ret_type llvm::cast<llvm::Operator, llvm::User const>(llvm::User const*) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/include/llvm/Support/Casting.h:255:0
#9 0x0000000001352326 llvm::TargetTransformInfoImplCRTPBase<llvm::X86TTIImpl>::getGEPCost(llvm::GEPOperator const*, llvm::ArrayRef<llvm::Value const*>) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h:742:0
#10 0x000000000135266d llvm::TargetTransformInfoImplCRTPBase<llvm::X86TTIImpl>::getUserCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h:782:0
#11 0x00000000016eab12 llvm::TargetTransformInfo::getUserCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>) const /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/Analysis/TargetTransformInfo.cpp:116:0
#12 0x0000000002051b06 llvm::SmallVectorTemplateCommon<llvm::Value const*, void>::begin() /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/include/llvm/ADT/SmallVector.h:116:0
#13 0x0000000002051b06 llvm::SmallVectorImpl<llvm::Value const*>::~SmallVectorImpl() /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/include/llvm/ADT/SmallVector.h:343:0
#14 0x0000000002051b06 llvm::SmallVector<llvm::Value const*, 4u>::~SmallVector() /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/include/llvm/ADT/SmallVector.h:864:0
#15 0x0000000002051b06 llvm::TargetTransformInfo::getUserCost(llvm::User const*) const /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/include/llvm/Analysis/TargetTransformInfo.h:285:0
#16 0x0000000002051b06 ComputeSpeculationCost(llvm::User const*, llvm::TargetTransformInfo const&) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/Transforms/Utils/SimplifyCFG.cpp:299:0
#17 0x000000000205e167 SpeculativelyExecuteBB(llvm::BranchInst*, llvm::BasicBlock*, llvm::TargetTransformInfo const&) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/Transforms/Utils/SimplifyCFG.cpp:2003:0
#18 0x00000000020651a5 SimplifyCondBranch /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/Transforms/Utils/SimplifyCFG.cpp:5835:0
#19 0x00000000020651a5 run /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/Transforms/Utils/SimplifyCFG.cpp:5986:0
#20 0x00000000020651a5 llvm::SimplifyCFG(llvm::BasicBlock*, llvm::TargetTransformInfo const&, llvm::AssumptionCache*, llvm::SimplifyCFGOptions const&, llvm::SmallPtrSetImpl<llvm::BasicBlock*>*) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/Transforms/Utils/SimplifyCFG.cpp:6020:0
#21 0x0000000001ef709a iterativelySimplifyCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::AssumptionCache*, llvm::SimplifyCFGOptions const&) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp:148:0
#22 0x0000000001ef74ac simplifyFunctionCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::AssumptionCache*, llvm::SimplifyCFGOptions const&) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp:166:0
#23 0x0000000001ef8109 (anonymous namespace)::BaseCFGSimplifyPass::runOnFunction(llvm::Function&) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp:226:0
#24 0x0000000001afcfbb llvm::FPPassManager::runOnFunction(llvm::Function&) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/IR/LegacyPassManager.cpp:1514:0
#25 0x00000000015c1b0e RunPassOnSCC /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/Analysis/CallGraphSCCPass.cpp:156:0
#26 0x00000000015c1b0e RunAllPassesOnSCC /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/Analysis/CallGraphSCCPass.cpp:424:0
#27 0x00000000015c1b0e (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/Analysis/CallGraphSCCPass.cpp:479:0
#28 0x0000000001afcbbd runOnModule /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/IR/LegacyPassManager.cpp:1591:0
#29 0x0000000001afcbbd llvm::legacy::PassManagerImpl::run(llvm::Module&) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/lib/IR/LegacyPassManager.cpp:1694:0
#30 0x000000000213496e llvm::PrettyStackTraceString::~PrettyStackTraceString() /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/include/llvm/Support/PrettyStackTrace.h:52:0
#31 0x000000000213496e EmitAssembly /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/tools/clang/lib/CodeGen/BackendUtil.cpp:788:0
#32 0x000000000213496e clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/tools/clang/lib/CodeGen/BackendUtil.cpp:1145:0
#33 0x000000000281d997 std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >::~unique_ptr() /usr/include/c++/5/bits/unique_ptr.h:235:0
#34 0x000000000281d997 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:292:0
#35 0x0000000002bc0958 void std::swap<bool>(bool&, bool&) /usr/include/c++/5/bits/move.h:187:0
#36 0x0000000002bc0958 clang::ParseAST(clang::Sema&, bool, bool) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/tools/clang/lib/Parse/ParseAST.cpp:161:0
#37 0x000000000281ce2f clang::CodeGenAction::ExecuteAction() /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:1024:0
#38 0x00000000024d7746 clang::FrontendAction::Execute() /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:897:0
#39 0x00000000024a7f66 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:991:0
#40 0x0000000002565a12 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:252:0
#41 0x00000000009ec5a8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/tools/clang/tools/driver/cc1_main.cpp:221:0
#42 0x00000000009741d2 ExecuteCC1Tool /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/tools/clang/tools/driver/driver.cpp:309:0
#43 0x00000000009741d2 main /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/tools/clang/tools/driver/driver.cpp:388:0
#44 0x00007f835d273830 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x20830)
#45 0x00000000009e8eb9 _start (/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/clang_build/bin/clang-6.0+0x9e8eb9)
Stack dump:
0.      Program arguments: /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/clang_build/bin/clang-6.0 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -main-file-name path.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -coverage-notes-file /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/lib/msan/libcxx_msan_x86_64/src/libcxx_msan_x86_64-build/lib/CMakeFiles/cxx_experimental.dir/__/src/experimental/filesystem/path.cpp.gcno -nostdinc++ -resource-dir /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/clang_build/lib/clang/6.0.0 -D NDEBUG -D _LIBCPP_BUILDING_LIBRARY -D _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -I /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/libcxx/include -D NDEBUG -internal-isystem /usr/local/include -internal-isystem /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/clang_build/lib/clang/6.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wall -Wextra -W -Wwrite-strings -Wno-unused-parameter -Wno-long-long -Werror=return-type -Wno-user-defined-literals -Wno-covered-switch-default -Wno-error -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/lib/msan/libcxx_msan_x86_64/src/libcxx_msan_x86_64-build/lib -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fsanitize=memory -fsanitize-blacklist=/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/clang_build/lib/clang/6.0.0/msan_blacklist.txt -fsanitize-memory-track-origins=2 -fno-assume-sane-operator-new -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o CMakeFiles/cxx_experimental.dir/__/src/experimental/filesystem/path.cpp.o -x c++ /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/libcxx/src/experimental/filesystem/path.cpp 
1.      <eof> parser at end of file
2.      Per-module optimization passes
3.      Running pass 'CallGraph Pass Manager' on module '/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/libcxx/src/experimental/filesystem/path.cpp'.
4.      Running pass 'Simplify the CFG' on function '@_ZNKSt12experimental10filesystem2v14path16__root_directoryEv'
clang-6.0: error: unable to execute command: Aborted (core dumped)
clang-6.0: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 6.0.0 (trunk 314517)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/clang_build/./bin
clang-6.0: note: diagnostic msg: PLEASE submit a bug report to <a href="http://llvm.org/bugs/">http://llvm.org/bugs/</a> and include the crash backtrace, preprocessed source, and associated run script.
clang-6.0: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-6.0: note: diagnostic msg: /tmp/path-ecf8e5.cpp
clang-6.0: note: diagnostic msg: /tmp/path-ecf8e5.sh
clang-6.0: note: diagnostic msg: 

********************
make[6]: *** [lib/CMakeFiles/cxx_experimental.dir/__/src/experimental/filesystem/path.cpp.o] Error 254
make[6]: *** Waiting for unfinished jobs....
make[5]: *** [lib/CMakeFiles/cxx_experimental.dir/all] Error 2
make[4]: *** [all] Error 2
Scanning dependencies of target cxx_objects</pre></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 29, 2017 at 7:50 AM, Jun Bum Lim via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: junbuml<br>
Date: Fri Sep 29 07:50:16 2017<br>
New Revision: 314517<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=314517&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=314517&view=rev</a><br>
Log:<br>
Use the basic cost if a GEP is not used as addressing mode<br>
<br>
Summary:<br>
Currently, getGEPCost() returns TCC_FREE whenever a GEP is a legal addressing mode in the target.<br>
However, since it doesn't check its actual users, it will return FREE even in cases<br>
where the GEP cannot be folded away as a part of actual addressing mode.<br>
For example, if an user of the GEP is a call instruction taking the GEP as a parameter,<br>
then the GEP may not be folded in isel.<br>
<br>
Reviewers: hfinkel, efriedma, mcrosier, jingyue, haicheng<br>
<br>
Reviewed By: hfinkel<br>
<br>
Subscribers: javed.absar, llvm-commits<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D38085" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D38085</a><br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/<wbr>Analysis/TargetTransformInfo.h<br>
    llvm/trunk/include/llvm/<wbr>Analysis/<wbr>TargetTransformInfoImpl.h<br>
    llvm/trunk/include/llvm/<wbr>CodeGen/BasicTTIImpl.h<br>
    llvm/trunk/include/llvm/IR/<wbr>Operator.h<br>
    llvm/trunk/lib/Analysis/<wbr>TargetTransformInfo.cpp<br>
    llvm/trunk/lib/Transforms/<wbr>Scalar/NaryReassociate.cpp<br>
    llvm/trunk/lib/Transforms/<wbr>Scalar/<wbr>StraightLineStrengthReduce.cpp<br>
    llvm/trunk/test/Analysis/<wbr>CostModel/AArch64/gep.ll<br>
    llvm/trunk/test/Analysis/<wbr>CostModel/X86/vector_gep.ll<br>
<br>
Modified: llvm/trunk/include/llvm/<wbr>Analysis/TargetTransformInfo.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h?rev=314517&r1=314516&r2=314517&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/include/<wbr>llvm/Analysis/<wbr>TargetTransformInfo.h?rev=<wbr>314517&r1=314516&r2=314517&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/include/llvm/<wbr>Analysis/TargetTransformInfo.h (original)<br>
+++ llvm/trunk/include/llvm/<wbr>Analysis/TargetTransformInfo.h Fri Sep 29 07:50:16 2017<br>
@@ -193,6 +193,13 @@ public:<br>
   int getGEPCost(Type *PointeeType, const Value *Ptr,<br>
                  ArrayRef<const Value *> Operands) const;<br>
<br>
+  /// \brief Estimate the cost of a GEP operation when lowered.<br>
+  ///<br>
+  /// This user-based overload adds the ability to check if the GEP can be<br>
+  /// folded into its users.<br>
+  int getGEPCost(const GEPOperator *GEP,<br>
+                 ArrayRef<const Value *> Operands) const;<br>
+<br>
   /// \brief Estimate the cost of a EXT operation when lowered.<br>
   ///<br>
   /// The contract for this function is the same as \c getOperationCost except<br>
@@ -251,9 +258,9 @@ public:<br>
   /// \brief Estimate the cost of a given IR user when lowered.<br>
   ///<br>
   /// This can estimate the cost of either a ConstantExpr or Instruction when<br>
-  /// lowered. It has two primary advantages over the \c getOperationCost and<br>
-  /// \c getGEPCost above, and one significant disadvantage: it can only be<br>
-  /// used when the IR construct has already been formed.<br>
+  /// lowered. It has two primary advantages over the \c getOperationCost above,<br>
+  /// and one significant disadvantage: it can only be used when the IR<br>
+  /// construct has already been formed.<br>
   ///<br>
   /// The advantages are that it can inspect the SSA use graph to reason more<br>
   /// accurately about the cost. For example, all-constant-GEPs can often be<br>
@@ -932,6 +939,8 @@ public:<br>
   virtual int getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy) = 0;<br>
   virtual int getGEPCost(Type *PointeeType, const Value *Ptr,<br>
                          ArrayRef<const Value *> Operands) = 0;<br>
+  virtual int getGEPCost(const GEPOperator *GEP,<br>
+                         ArrayRef<const Value *> Operands) = 0;<br>
   virtual int getExtCost(const Instruction *I, const Value *Src) = 0;<br>
   virtual int getCallCost(FunctionType *FTy, int NumArgs) = 0;<br>
   virtual int getCallCost(const Function *F, int NumArgs) = 0;<br>
@@ -1113,6 +1122,10 @@ public:<br>
                  ArrayRef<const Value *> Operands) override {<br>
     return Impl.getGEPCost(PointeeType, Ptr, Operands);<br>
   }<br>
+  int getGEPCost(const GEPOperator *GEP,<br>
+                 ArrayRef<const Value *> Operands) override {<br>
+    return Impl.getGEPCost(GEP, Operands);<br>
+  }<br>
   int getExtCost(const Instruction *I, const Value *Src) override {<br>
     return Impl.getExtCost(I, Src);<br>
   }<br>
<br>
Modified: llvm/trunk/include/llvm/<wbr>Analysis/<wbr>TargetTransformInfoImpl.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h?rev=314517&r1=314516&r2=314517&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/include/<wbr>llvm/Analysis/<wbr>TargetTransformInfoImpl.h?rev=<wbr>314517&r1=314516&r2=314517&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/include/llvm/<wbr>Analysis/<wbr>TargetTransformInfoImpl.h (original)<br>
+++ llvm/trunk/include/llvm/<wbr>Analysis/<wbr>TargetTransformInfoImpl.h Fri Sep 29 07:50:16 2017<br>
@@ -726,6 +726,35 @@ public:<br>
     return TTI::TCC_Basic;<br>
   }<br>
<br>
+  int getGEPCost(const GEPOperator *GEP, ArrayRef<const Value *> Operands) {<br>
+    Type *PointeeType = GEP->getSourceElementType();<br>
+    const Value *Ptr = GEP->getPointerOperand();<br>
+<br>
+    if (getGEPCost(PointeeType, Ptr, Operands) == TTI::TCC_Free) {<br>
+      // Should check if the GEP is actually used in load / store instructions.<br>
+      // For simplicity, we check only direct users of the GEP.<br>
+      //<br>
+      // FIXME: GEPs could also be folded away as a part of addressing mode in<br>
+      // load/store instructions together with other instructions (e.g., other<br>
+      // GEPs). Handling all such cases must be expensive to be performed<br>
+      // in this function, so we stay conservative for now.<br>
+      for (const User *U : GEP->users()) {<br>
+        const Operator *UOP = cast<Operator>(U);<br>
+        const Value *PointerOperand = nullptr;<br>
+        if (auto *LI = dyn_cast<LoadInst>(UOP))<br>
+          PointerOperand = LI->getPointerOperand();<br>
+        else if (auto *SI = dyn_cast<StoreInst>(UOP))<br>
+          PointerOperand = SI->getPointerOperand();<br>
+<br>
+        if ((!PointerOperand || PointerOperand != GEP) &&<br>
+            !GEP->hasAllZeroIndices())<br>
+          return TTI::TCC_Basic;<br>
+      }<br>
+      return TTI::TCC_Free;<br>
+    }<br>
+    return TTI::TCC_Basic;<br>
+  }<br>
+<br>
   using BaseT::getIntrinsicCost;<br>
<br>
   unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,<br>
@@ -749,11 +778,8 @@ public:<br>
       if (A->isStaticAlloca())<br>
         return TTI::TCC_Free;<br>
<br>
-    if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) {<br>
-      return static_cast<T *>(this)->getGEPCost(GEP-><wbr>getSourceElementType(),<br>
-                                                GEP->getPointerOperand(),<br>
-                                                Operands.drop_front());<br>
-    }<br>
+    if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U))<br>
+      return static_cast<T *>(this)->getGEPCost(GEP, Operands.drop_front());<br>
<br>
     if (auto CS = ImmutableCallSite(U)) {<br>
       const Function *F = CS.getCalledFunction();<br>
<br>
Modified: llvm/trunk/include/llvm/<wbr>CodeGen/BasicTTIImpl.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/BasicTTIImpl.h?rev=314517&r1=314516&r2=314517&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/include/<wbr>llvm/CodeGen/BasicTTIImpl.h?<wbr>rev=314517&r1=314516&r2=<wbr>314517&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/include/llvm/<wbr>CodeGen/BasicTTIImpl.h (original)<br>
+++ llvm/trunk/include/llvm/<wbr>CodeGen/BasicTTIImpl.h Fri Sep 29 07:50:16 2017<br>
@@ -151,6 +151,10 @@ public:<br>
     return BaseT::getGEPCost(PointeeType, Ptr, Operands);<br>
   }<br>
<br>
+  int getGEPCost(const GEPOperator *GEP, ArrayRef<const Value *> Operands) {<br>
+    return BaseT::getGEPCost(GEP, Operands);<br>
+  }<br>
+<br>
   int getExtCost(const Instruction *I, const Value *Src) {<br>
     if (getTLI()->isExtFree(I))<br>
       return TargetTransformInfo::TCC_Free;<br>
<br>
Modified: llvm/trunk/include/llvm/IR/<wbr>Operator.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Operator.h?rev=314517&r1=314516&r2=314517&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/include/<wbr>llvm/IR/Operator.h?rev=314517&<wbr>r1=314516&r2=314517&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/include/llvm/IR/<wbr>Operator.h (original)<br>
+++ llvm/trunk/include/llvm/IR/<wbr>Operator.h Fri Sep 29 07:50:16 2017<br>
@@ -456,6 +456,8 @@ public:<br>
       if (ConstantInt *C = dyn_cast<ConstantInt>(I))<br>
         if (C->isZero())<br>
           continue;<br>
+      if (isa<ConstantAggregateZero>(I)<wbr>)<br>
+        continue;<br>
       return false;<br>
     }<br>
     return true;<br>
<br>
Modified: llvm/trunk/lib/Analysis/<wbr>TargetTransformInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/TargetTransformInfo.cpp?rev=314517&r1=314516&r2=314517&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>Analysis/TargetTransformInfo.<wbr>cpp?rev=314517&r1=314516&r2=<wbr>314517&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/Analysis/<wbr>TargetTransformInfo.cpp (original)<br>
+++ llvm/trunk/lib/Analysis/<wbr>TargetTransformInfo.cpp Fri Sep 29 07:50:16 2017<br>
@@ -88,6 +88,11 @@ int TargetTransformInfo::<wbr>getGEPCost(Type<br>
   return TTIImpl->getGEPCost(<wbr>PointeeType, Ptr, Operands);<br>
 }<br>
<br>
+int TargetTransformInfo::<wbr>getGEPCost(const GEPOperator *GEP,<br>
+                                    ArrayRef<const Value *> Operands) const {<br>
+  return TTIImpl->getGEPCost(GEP, Operands);<br>
+}<br>
+<br>
 int TargetTransformInfo::<wbr>getExtCost(const Instruction *I,<br>
                                     const Value *Src) const {<br>
   return TTIImpl->getExtCost(I, Src);<br>
<br>
Modified: llvm/trunk/lib/Transforms/<wbr>Scalar/NaryReassociate.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/NaryReassociate.cpp?rev=314517&r1=314516&r2=314517&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>Transforms/Scalar/<wbr>NaryReassociate.cpp?rev=<wbr>314517&r1=314516&r2=314517&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/Transforms/<wbr>Scalar/NaryReassociate.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/<wbr>Scalar/NaryReassociate.cpp Fri Sep 29 07:50:16 2017<br>
@@ -264,7 +264,7 @@ static bool isGEPFoldable(GetElementPtrI<br>
   SmallVector<const Value*, 4> Indices;<br>
   for (auto I = GEP->idx_begin(); I != GEP->idx_end(); ++I)<br>
     Indices.push_back(*I);<br>
-  return TTI->getGEPCost(GEP-><wbr>getSourceElementType(), GEP->getPointerOperand(),<br>
+  return TTI->getGEPCost(cast<<wbr>GEPOperator>(GEP),<br>
                          Indices) == TargetTransformInfo::TCC_Free;<br>
 }<br>
<br>
<br>
Modified: llvm/trunk/lib/Transforms/<wbr>Scalar/<wbr>StraightLineStrengthReduce.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp?rev=314517&r1=314516&r2=314517&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>Transforms/Scalar/<wbr>StraightLineStrengthReduce.<wbr>cpp?rev=314517&r1=314516&r2=<wbr>314517&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/Transforms/<wbr>Scalar/<wbr>StraightLineStrengthReduce.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/<wbr>Scalar/<wbr>StraightLineStrengthReduce.cpp Fri Sep 29 07:50:16 2017<br>
@@ -239,7 +239,7 @@ static bool isGEPFoldable(GetElementPtrI<br>
   SmallVector<const Value*, 4> Indices;<br>
   for (auto I = GEP->idx_begin(); I != GEP->idx_end(); ++I)<br>
     Indices.push_back(*I);<br>
-  return TTI->getGEPCost(GEP-><wbr>getSourceElementType(), GEP->getPointerOperand(),<br>
+  return TTI->getGEPCost(cast<<wbr>GEPOperator>(GEP),<br>
                          Indices) == TargetTransformInfo::TCC_Free;<br>
 }<br>
<br>
<br>
Modified: llvm/trunk/test/Analysis/<wbr>CostModel/AArch64/gep.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CostModel/AArch64/gep.ll?rev=314517&r1=314516&r2=314517&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/<wbr>Analysis/CostModel/AArch64/<wbr>gep.ll?rev=314517&r1=314516&<wbr>r2=314517&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/test/Analysis/<wbr>CostModel/AArch64/gep.ll (original)<br>
+++ llvm/trunk/test/Analysis/<wbr>CostModel/AArch64/gep.ll Fri Sep 29 07:50:16 2017<br>
@@ -290,3 +290,49 @@ define i64 @test36(i64* %p) {<br>
   %v = load i64, i64* %a<br>
   ret i64 %v<br>
 }<br>
+<br>
+; CHECK-LABEL: test37<br>
+; CHECK: cost of 1 for instruction:  {{.*}} = getelementptr inbounds i8*, i8**<br>
+define i8 @test37(i64 %j, i8** readonly %P) {<br>
+entry:<br>
+  %arrayidx0 = getelementptr inbounds i8*, i8** %P, i64 %j<br>
+  %l1 = call i8* @func(i8** %arrayidx0)<br>
+  ret i8 0<br>
+}<br>
+<br>
+; CHECK-LABEL: test38<br>
+; CHECK: cost of 1 for instruction: {{.*}} = getelementptr inbounds i8*, i8**<br>
+define i8 @test38(i8** readonly %P) {<br>
+entry:<br>
+  %arrayidx0 = getelementptr inbounds i8*, i8** %P, i64 10<br>
+  %l1 = call i8* @func(i8** %arrayidx0)<br>
+  ret i8 0<br>
+}<br>
+<br>
+; CHECK-LABEL:test39<br>
+; CHECK: cost of 0 for instruction: {{.*}} = getelementptr inbounds i8*, i8**<br>
+define i8 @test39(i8** readonly %P) {<br>
+entry:<br>
+  %arrayidx0 = getelementptr inbounds i8*, i8** %P, i64 0<br>
+  %l1 = call i8* @func(i8** %arrayidx0)<br>
+  ret i8 0<br>
+}<br>
+<br>
+; CHECK-LABEL:test40<br>
+; CHECK: cost of 1 for instruction: {{.*}} = getelementptr inbounds i8*, i8**<br>
+define i8** @test40(i8** readonly %P) {<br>
+entry:<br>
+  %arrayidx0 = getelementptr inbounds i8*, i8** %P, i64 10<br>
+  ret i8** %arrayidx0<br>
+}<br>
+<br>
+; CHECK-LABEL:test41<br>
+; CHECK: cost of 1 for instruction: {{.*}} = getelementptr inbounds i8, i8*<br>
+define i8 @test41(i8* %V, i8** readonly %P) {<br>
+entry:<br>
+  %arrayidx0 = getelementptr inbounds i8, i8* %V, i64 10<br>
+  store i8* %arrayidx0, i8** %P<br>
+  ret i8 0<br>
+}<br>
+<br>
+declare i8* @func(i8**)<br>
<br>
Modified: llvm/trunk/test/Analysis/<wbr>CostModel/X86/vector_gep.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CostModel/X86/vector_gep.ll?rev=314517&r1=314516&r2=314517&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/<wbr>Analysis/CostModel/X86/vector_<wbr>gep.ll?rev=314517&r1=314516&<wbr>r2=314517&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/test/Analysis/<wbr>CostModel/X86/vector_gep.ll (original)<br>
+++ llvm/trunk/test/Analysis/<wbr>CostModel/X86/vector_gep.ll Fri Sep 29 07:50:16 2017<br>
@@ -10,7 +10,7 @@ define <4 x i32> @foov(<4 x %struct.S*><br>
   %vector = shufflevector <4 x i64> %temp, <4 x i64> undef, <4 x i32> zeroinitializer<br>
 ;CHECK: cost of 0 for instruction: {{.*}} getelementptr inbounds %struct.S<br>
   %B = getelementptr inbounds %struct.S, <4 x %struct.S*> %s, <4 x i32> zeroinitializer, <4 x i32> zeroinitializer<br>
-;CHECK: cost of 0 for instruction: {{.*}} getelementptr inbounds [1000 x i32]<br>
+;CHECK: cost of 1 for instruction: {{.*}} getelementptr inbounds [1000 x i32]<br>
   %arrayidx = getelementptr inbounds [1000 x i32], <4 x [1000 x i32]*> %B, <4 x i64> zeroinitializer, <4 x i64> %vector<br>
   %res = call <4 x i32> @llvm.masked.gather.v4i32.<wbr>v4p0i32(<4 x i32*> %arrayidx, i32 4, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x i32> undef)<br>
   ret <4 x i32> %res<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>