[llvm] adc4faf - [IndVarSimplify] Teach IndVarSimplify to preserve MemorySSA.

Mikael Holmén via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 23 23:31:16 PST 2020


On Thu, 2020-01-23 at 11:27 -0800, Alina Sbirlea wrote:
> Thanks for the catch! Should be resolved by rGa0f627d5842.

Yep, thanks!

/Mikael

> 
> Alina
> 
> On Thu, Jan 23, 2020 at 4:01 AM Mikael Holmén <
> mikael.holmen at ericsson.com> wrote:
> > Hi Alina,
> > 
> > I noticed that the following started hitting an assertion with this
> > patch:
> > 
> > opt -S -o - foo.ll -licm -indvars -licm
> > 
> > gives me
> > 
> > opt: ../lib/Analysis/MemorySSA.cpp:2028: void
> > llvm::MemorySSA::verifyOrderingDominationAndDefUses(llvm::Function
> > &)
> > const: Assertion `AL->size() == ActualAccesses.size() && "We don't
> > have
> > the same number of accesses in the block as on the " "access list"'
> > failed.
> > Stack dump:
> > 0.      Program arguments: /data/repo/master/llvm/build-all-
> > builtins/bin/opt -S -o - foo.ll -licm -indvars -licm 
> > 1.      Running pass 'Function Pass Manager' on module 'foo.ll'.
> > 2.      Running pass 'Loop Pass Manager' on function '@v_2_0'
> >  #0 0x0000000003e7dcf4 PrintStackTraceSignalHandler(void*)
> > (/data/repo/master/llvm/build-all-builtins/bin/opt+0x3e7dcf4)
> >  #1 0x0000000003e7b8be llvm::sys::RunSignalHandlers()
> > (/data/repo/master/llvm/build-all-builtins/bin/opt+0x3e7b8be)
> >  #2 0x0000000003e7e0fc SignalHandler(int)
> > (/data/repo/master/llvm/build-all-builtins/bin/opt+0x3e7e0fc)
> >  #3 0x00007f45cb006890 __restore_rt (/lib/x86_64-linux-
> > gnu/libpthread.so.0+0x12890)
> >  #4 0x00007f45c9aafe97 raise /build/glibc-OTsEL5/glibc-
> > 2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
> >  #5 0x00007f45c9ab1801 abort /build/glibc-OTsEL5/glibc-
> > 2.27/stdlib/abort.c:81:0
> >  #6 0x00007f45c9aa139a __assert_fail_base /build/glibc-
> > OTsEL5/glibc-
> > 2.27/assert/assert.c:89:0
> >  #7 0x00007f45c9aa1412 (/lib/x86_64-linux-gnu/libc.so.6+0x30412)
> >  #8 0x00000000030c8daa
> > llvm::MemorySSA::verifyOrderingDominationAndDefUses(llvm::Function&
> > )
> > const (/data/repo/master/llvm/build-all-builtins/bin/opt+0x30c8daa)
> >  #9 0x00000000030cb381 llvm::MemorySSAWrapperPass::verifyAnalysis()
> > const (/data/repo/master/llvm/build-all-builtins/bin/opt+0x30cb381)
> > #10 0x00000000036fb939
> > llvm::PMDataManager::verifyPreservedAnalysis(llvm::Pass*)
> > (/data/repo/master/llvm/build-all-builtins/bin/opt+0x36fb939)
> > #11 0x00000000030a3bd6
> > llvm::LPPassManager::runOnFunction(llvm::Function&)
> > (/data/repo/master/llvm/build-all-builtins/bin/opt+0x30a3bd6)
> > #12 0x00000000036fefd3
> > llvm::FPPassManager::runOnFunction(llvm::Function&)
> > (/data/repo/master/llvm/build-all-builtins/bin/opt+0x36fefd3)
> > #13 0x00000000036ff2b8
> > llvm::FPPassManager::runOnModule(llvm::Module&)
> > (/data/repo/master/llvm/build-all-builtins/bin/opt+0x36ff2b8)
> > #14 0x00000000036ff91d
> > llvm::legacy::PassManagerImpl::run(llvm::Module&)
> > (/data/repo/master/llvm/build-all-builtins/bin/opt+0x36ff91d)
> > #15 0x0000000002095a93 main (/data/repo/master/llvm/build-all-
> > builtins/bin/opt+0x2095a93)
> > #16 0x00007f45c9a92b97 __libc_start_main /build/glibc-OTsEL5/glibc-
> > 2.27/csu/../csu/libc-start.c:344:0
> > #17 0x000000000207d02a _start (/data/repo/master/llvm/build-all-
> > builtins/bin/opt+0x207d02a)
> > Abort (core dumped)
> > 
> > /Mikael
> > 
> > On Wed, 2020-01-22 at 16:39 -0800, Alina Sbirlea via llvm-commits
> > wrote:
> > > Author: Alina Sbirlea
> > > Date: 2020-01-22T16:33:17-08:00
> > > New Revision: adc4faf532bfefeddb4c789f1562394ae2a1ba0d
> > > 
> > > URL: 
> > > 
> > https://protect2.fireeye.com/v1/url?k=f7eee798-ab7ceac4-f7eea703-0cc47ad93d46-8ded1b8e9d278649&q=1&e=01022273-bea5-4c6e-8983-d20037c15100&u=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fcommit%2Fadc4faf532bfefeddb4c789f1562394ae2a1ba0d
> > > DIFF: 
> > > 
> > https://protect2.fireeye.com/v1/url?k=8ac1daa5-d653d7f9-8ac19a3e-0cc47ad93d46-571f46367ac21f72&q=1&e=01022273-bea5-4c6e-8983-d20037c15100&u=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fcommit%2Fadc4faf532bfefeddb4c789f1562394ae2a1ba0d.diff
> > > 
> > > LOG: [IndVarSimplify] Teach IndVarSimplify to preserve MemorySSA.
> > > 
> > > Added: 
> > >     
> > > 
> > > Modified: 
> > >     llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
> > > 
> > > Removed: 
> > >     
> > > 
> > > 
> > >
> > ###################################################################
> > ##
> > > ###########
> > > diff  --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
> > > b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
> > > index a14049543236..259b6aec7b34 100644
> > > --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
> > > +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
> > > @@ -38,6 +38,8 @@
> > >  #include "llvm/ADT/iterator_range.h"
> > >  #include "llvm/Analysis/LoopInfo.h"
> > >  #include "llvm/Analysis/LoopPass.h"
> > > +#include "llvm/Analysis/MemorySSA.h"
> > > +#include "llvm/Analysis/MemorySSAUpdater.h"
> > >  #include "llvm/Analysis/ScalarEvolution.h"
> > >  #include "llvm/Analysis/ScalarEvolutionExpander.h"
> > >  #include "llvm/Analysis/ScalarEvolutionExpressions.h"
> > > @@ -138,6 +140,8 @@ class IndVarSimplify {
> > >    const DataLayout &DL;
> > >    TargetLibraryInfo *TLI;
> > >    const TargetTransformInfo *TTI;
> > > +  MemorySSA *MSSA;
> > > +  std::unique_ptr<MemorySSAUpdater> MSSAU;
> > >  
> > >    SmallVector<WeakTrackingVH, 16> DeadInsts;
> > >  
> > > @@ -162,8 +166,11 @@ class IndVarSimplify {
> > >  public:
> > >    IndVarSimplify(LoopInfo *LI, ScalarEvolution *SE,
> > DominatorTree
> > > *DT,
> > >                   const DataLayout &DL, TargetLibraryInfo *TLI,
> > > -                 TargetTransformInfo *TTI)
> > > -      : LI(LI), SE(SE), DT(DT), DL(DL), TLI(TLI), TTI(TTI) {}
> > > +                 TargetTransformInfo *TTI, MemorySSA *MSSA)
> > > +      : LI(LI), SE(SE), DT(DT), DL(DL), TLI(TLI), TTI(TTI),
> > > MSSA(MSSA) {
> > > +    if (MSSA)
> > > +      MSSAU = std::make_unique<MemorySSAUpdater>(MSSA);
> > > +  }
> > >  
> > >    bool run(Loop *L);
> > >  };
> > > @@ -418,11 +425,11 @@ bool
> > IndVarSimplify::handleFloatingPointIV(Loop
> > > *L, PHINode *PN) {
> > >    // new comparison.
> > >    NewCompare->takeName(Compare);
> > >    Compare->replaceAllUsesWith(NewCompare);
> > > -  RecursivelyDeleteTriviallyDeadInstructions(Compare, TLI);
> > > +  RecursivelyDeleteTriviallyDeadInstructions(Compare, TLI,
> > > MSSAU.get());
> > >  
> > >    // Delete the old floating point increment.
> > >    Incr->replaceAllUsesWith(UndefValue::get(Incr->getType()));
> > > -  RecursivelyDeleteTriviallyDeadInstructions(Incr, TLI);
> > > +  RecursivelyDeleteTriviallyDeadInstructions(Incr, TLI,
> > > MSSAU.get());
> > >  
> > >    // If the FP induction variable still has uses, this is
> > because
> > > something else
> > >    // in the loop uses its value.  In order to canonicalize the
> > > induction
> > > @@ -435,7 +442,7 @@ bool
> > IndVarSimplify::handleFloatingPointIV(Loop
> > > *L, PHINode *PN) {
> > >      Value *Conv = new SIToFPInst(NewPHI, PN->getType(),
> > > "indvar.conv",
> > >                                   &*PN->getParent()-
> > > >getFirstInsertionPt());
> > >      PN->replaceAllUsesWith(Conv);
> > > -    RecursivelyDeleteTriviallyDeadInstructions(PN, TLI);
> > > +    RecursivelyDeleteTriviallyDeadInstructions(PN, TLI,
> > > MSSAU.get());
> > >    }
> > >    return true;
> > >  }
> > > @@ -2823,12 +2830,14 @@ PreservedAnalyses
> > > IndVarSimplifyPass::run(Loop &L, LoopAnalysisManager &AM,
> > >    Function *F = L.getHeader()->getParent();
> > >    const DataLayout &DL = F->getParent()->getDataLayout();
> > >  
> > > -  IndVarSimplify IVS(&AR.LI, &AR.SE, &AR.DT, DL, &AR.TLI,
> > &AR.TTI);
> > > +  IndVarSimplify IVS(&AR.LI, &AR.SE, &AR.DT, DL, &AR.TLI,
> > &AR.TTI,
> > > AR.MSSA);
> > >    if (!IVS.run(&L))
> > >      return PreservedAnalyses::all();
> > >  
> > >    auto PA = getLoopPassPreservedAnalyses();
> > >    PA.preserveSet<CFGAnalyses>();
> > > +  if (AR.MSSA)
> > > +    PA.preserve<MemorySSAAnalysis>();
> > >    return PA;
> > >  }
> > >  
> > > @@ -2853,13 +2862,18 @@ struct IndVarSimplifyLegacyPass : public
> > > LoopPass {
> > >      auto *TTIP =
> > > getAnalysisIfAvailable<TargetTransformInfoWrapperPass>();
> > >      auto *TTI = TTIP ? &TTIP->getTTI(*L->getHeader()-
> > >getParent()) :
> > > nullptr;
> > >      const DataLayout &DL = L->getHeader()->getModule()-
> > > >getDataLayout();
> > > +    auto *MSSAAnalysis =
> > > getAnalysisIfAvailable<MemorySSAWrapperPass>();
> > > +    MemorySSA *MSSA = nullptr;
> > > +    if (MSSAAnalysis)
> > > +      MSSA = &MSSAAnalysis->getMSSA();
> > >  
> > > -    IndVarSimplify IVS(LI, SE, DT, DL, TLI, TTI);
> > > +    IndVarSimplify IVS(LI, SE, DT, DL, TLI, TTI, MSSA);
> > >      return IVS.run(L);
> > >    }
> > >  
> > >    void getAnalysisUsage(AnalysisUsage &AU) const override {
> > >      AU.setPreservesCFG();
> > > +    AU.addPreserved<MemorySSAWrapperPass>();
> > >      getLoopAnalysisUsage(AU);
> > >    }
> > >  };
> > > 
> > > 
> > >         
> > > _______________________________________________
> > > llvm-commits mailing list
> > > llvm-commits at lists.llvm.org
> > > 
> > 
https://protect2.fireeye.com/v1/url?k=5a03034f-06910e13-5a0343d4-0cc47ad93d46-75959173d0d21924&q=1&e=01022273-bea5-4c6e-8983-d20037c15100&u=https%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fllvm-commits


More information about the llvm-commits mailing list