[llvm] 952c274 - [RDA] Use TinyPtrVector to store reaching defs (NFCI)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 9 01:55:22 PDT 2020


On Thu, Apr 9, 2020 at 7:53 AM Mikael Holmén <mikael.holmen at ericsson.com>
wrote:

> Hi,
>
> In our downstream bots running with sanitizers we see lots of
> complaints like
>
> ../include/llvm/CodeGen/ReachingDefAnalysis.h:47:43: runtime error:
> left shift of negative value -1
>
> I haven't verified that they really start occuring with this patch, but
> the left shift it complains on was at least added here.
>
> I think the same can be seen here:
> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast
>
> /Mikael
>

Thanks for the pointer! This should be fixed with
https://github.com/llvm/llvm-project/commit/8f66f25f52f9b4089d216a33283acdb87ea3c250
.

Regards,
Nikita

On Wed, 2020-04-08 at 08:52 -0700, Nikita Popov via llvm-commits wrote:
> > Author: Nikita Popov
> > Date: 2020-04-08T17:46:24+02:00
> > New Revision: 952c2741599ed492cedd37da895d7e81bc175ab9
> >
> > URL:
> >
> https://github.com/llvm/llvm-project/commit/952c2741599ed492cedd37da895d7e81bc175ab9
> > DIFF:
> >
> https://github.com/llvm/llvm-project/commit/952c2741599ed492cedd37da895d7e81bc175ab9.diff
> >
> > LOG: [RDA] Use TinyPtrVector to store reaching defs (NFCI)
> >
> > RDA currently uses SmallVector<int, 1> to store reaching definitions.
> > A SmallVector<int, 1> is 24 bytes large, and X86 currently has
> > 164 register units, which means we need 3936 bytes per block.
> > If you have a large function with 1000 blocks, that's already 4MB.
> >
> > A large fraction of these reg units will not have any reaching defs
> > (say, those corresponding to zmm registers), and many will have just
> > one. A TinyPtrVector serves this use-case much better, as it only
> > needs 8 bytes per register if it has 0 or 1 reaching defs.
> >
> > As the name implies, TinyPtrVector is designed to work with pointers,
> > so we need to add some boilerplate to treat our reaching def integers
> > as pointers, using an appropriate encoding. We need to keep the low
> > bit free for tagging, and make sure at least one bit is set to
> > distinguish the null pointer.
> >
> > Differential Revision: https://reviews.llvm.org/D77513
> >
> > Added:
> >
> >
> > Modified:
> >     llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
> >
> > Removed:
> >
> >
> >
> > #####################################################################
> > ###########
> > diff  --git a/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
> > b/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
> > index 608f0dff4ccb..8def1a6d39fc 100644
> > --- a/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
> > +++ b/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
> > @@ -23,6 +23,7 @@
> >
> >  #include "llvm/ADT/DenseMap.h"
> >  #include "llvm/ADT/SmallVector.h"
> > +#include "llvm/ADT/TinyPtrVector.h"
> >  #include "llvm/CodeGen/LoopTraversal.h"
> >  #include "llvm/CodeGen/MachineFunctionPass.h"
> >  #include "llvm/InitializePasses.h"
> > @@ -32,6 +33,37 @@ namespace llvm {
> >  class MachineBasicBlock;
> >  class MachineInstr;
> >
> > +/// Thin wrapper around "int" used to store reaching definitions,
> > +/// using an encoding that makes it compatible with TinyPtrVector.
> > +/// The 0th LSB is forced zero (and will be used for pointer union
> > tagging),
> > +/// The 1st LSB is forced one (to make sure the value is non-zero).
> > +class ReachingDef {
> > +  uintptr_t Encoded;
> > +  friend struct PointerLikeTypeTraits<ReachingDef>;
> > +  explicit ReachingDef(uintptr_t Encoded) : Encoded(Encoded) {}
> > +
> > +public:
> > +  ReachingDef(int Instr) : Encoded((Instr << 2) | 2) {}
> > +  operator int() const { return ((int) Encoded) >> 2; }
> > +};
> > +
> > +template<>
> > +struct PointerLikeTypeTraits<ReachingDef> {
> > +  static constexpr int NumLowBitsAvailable = 1;
> > +
> > +  static inline void *getAsVoidPointer(const ReachingDef &RD) {
> > +    return reinterpret_cast<void *>(RD.Encoded);
> > +  }
> > +
> > +  static inline ReachingDef getFromVoidPointer(void *P) {
> > +    return ReachingDef(reinterpret_cast<uintptr_t>(P));
> > +  }
> > +
> > +  static inline ReachingDef getFromVoidPointer(const void *P) {
> > +    return ReachingDef(reinterpret_cast<uintptr_t>(P));
> > +  }
> > +};
> > +
> >  /// This class provides the reaching def analysis.
> >  class ReachingDefAnalysis : public MachineFunctionPass {
> >  private:
> > @@ -61,7 +93,7 @@ class ReachingDefAnalysis : public
> > MachineFunctionPass {
> >    DenseMap<MachineInstr *, int> InstIds;
> >
> >    /// All reaching defs of a given RegUnit for a given MBB.
> > -  using MBBRegUnitDefs = SmallVector<int, 1>;
> > +  using MBBRegUnitDefs = TinyPtrVector<ReachingDef>;
> >    /// All reaching defs of all reg units for a given MBB
> >    using MBBDefsInfo = std::vector<MBBRegUnitDefs>;
> >    /// All reaching defs of all reg units for a all MBBs
> >
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200409/e824b7f5/attachment.html>


More information about the llvm-commits mailing list