[polly] r288516 - Do not allow multiple possibly aliasing ptrs in an expression

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 6 06:06:42 PST 2016


Hi Michael,

On 12/06, Michael Kruse wrote:
> do you have a test case for this?
I do not have a test case written or distilled right now, sry. I wrote
this in a hurry last week.

Cheers,
  JD

P.S.
This patch avoids 2.5 million failing runtime checks for a loop in the
SPEC2000/253.perlbmk Perl_my_bcopy function. I missed to add that to the
commit message.

> 2016-12-02 18:49 GMT+01:00 Johannes Doerfert via llvm-commits
> <llvm-commits at lists.llvm.org>:
> > Author: jdoerfert
> > Date: Fri Dec  2 11:49:52 2016
> > New Revision: 288516
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=288516&view=rev
> > Log:
> > Do not allow multiple possibly aliasing ptrs in an expression
> >
> >   Relational comparisons should not involve multiple potentially
> >   aliasing pointers. Similarly this should hold for switch conditions
> >   and the two conditions involved in equality comparisons (separately!).
> >   This is a heuristic based on the C semantics that does only allow such
> >   operations when the base pointers do point into the same object.
> >   Since this makes aliasing likely we will bail out early instead of
> >   producing a probably failing runtime check.
> >
> > Modified:
> >     polly/trunk/include/polly/ScopDetection.h
> >     polly/trunk/lib/Analysis/ScopDetection.cpp
> >
> > Modified: polly/trunk/include/polly/ScopDetection.h
> > URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopDetection.h?rev=288516&r1=288515&r2=288516&view=diff
> > ==============================================================================
> > --- polly/trunk/include/polly/ScopDetection.h (original)
> > +++ polly/trunk/include/polly/ScopDetection.h Fri Dec  2 11:49:52 2016
> > @@ -219,6 +219,16 @@ private:
> >    /// Remove cached results for the children of @p R recursively.
> >    void removeCachedResultsRecursively(const Region &R);
> >
> > +  /// Check if @p S0 and @p S1 do contain multiple possibly aliasing pointers.
> > +  ///
> > +  /// @param S0    A expression to check.
> > +  /// @param S1    Another expression to check or nullptr.
> > +  /// @param Scope The loop/scope the expressions are checked in.
> > +  ///
> > +  /// @returns True, if multiple possibly aliasing pointers are used in @p S0
> > +  ///          (and @p S1 if given).
> > +  bool involvesMultiplePtrs(const SCEV *S0, const SCEV *S1, Loop *Scope) const;
> > +
> >    /// Add the region @p AR as over approximated sub-region in @p Context.
> >    ///
> >    /// @param AR      The non-affine subregion.
> >
> > Modified: polly/trunk/lib/Analysis/ScopDetection.cpp
> > URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetection.cpp?rev=288516&r1=288515&r2=288516&view=diff
> > ==============================================================================
> > --- polly/trunk/lib/Analysis/ScopDetection.cpp (original)
> > +++ polly/trunk/lib/Analysis/ScopDetection.cpp Fri Dec  2 11:49:52 2016
> > @@ -346,6 +346,40 @@ bool ScopDetection::onlyValidRequiredInv
> >    return true;
> >  }
> >
> > +bool ScopDetection::involvesMultiplePtrs(const SCEV *S0, const SCEV *S1,
> > +                                         Loop *Scope) const {
> > +  SetVector<Value *> Values;
> > +  findValues(S0, *SE, Values);
> > +  if (S1)
> > +    findValues(S1, *SE, Values);
> > +
> > +  SmallPtrSet<Value *, 8> PtrVals;
> > +  for (auto *V : Values) {
> > +    if (auto *P2I = dyn_cast<PtrToIntInst>(V))
> > +      V = P2I->getOperand(0);
> > +
> > +    if (!V->getType()->isPointerTy())
> > +      continue;
> > +
> > +    auto *PtrSCEV = SE->getSCEVAtScope(V, Scope);
> > +    if (isa<SCEVConstant>(PtrSCEV))
> > +      continue;
> > +
> > +    auto *BasePtr = dyn_cast<SCEVUnknown>(SE->getPointerBase(PtrSCEV));
> > +    if (!BasePtr)
> > +      return true;
> > +
> > +    auto *BasePtrVal = BasePtr->getValue();
> > +    if (PtrVals.insert(BasePtrVal).second) {
> > +      for (auto *PtrVal : PtrVals)
> > +        if (PtrVal != BasePtrVal && !AA->isNoAlias(PtrVal, BasePtrVal))
> > +          return true;
> > +    }
> > +  }
> > +
> > +  return false;
> > +}
> > +
> >  bool ScopDetection::isAffine(const SCEV *S, Loop *Scope,
> >                               DetectionContext &Context) const {
> >
> > @@ -368,6 +402,10 @@ bool ScopDetection::isValidSwitch(BasicB
> >    if (IsLoopBranch && L->isLoopLatch(&BB))
> >      return false;
> >
> > +  // Check for invalid usage of different pointers in one expression.
> > +  if (involvesMultiplePtrs(ConditionSCEV, nullptr, L))
> > +    return false;
> > +
> >    if (isAffine(ConditionSCEV, L, Context))
> >      return true;
> >
> > @@ -416,6 +454,15 @@ bool ScopDetection::isValidBranch(BasicB
> >    const SCEV *LHS = SE->getSCEVAtScope(ICmp->getOperand(0), L);
> >    const SCEV *RHS = SE->getSCEVAtScope(ICmp->getOperand(1), L);
> >
> > +  // Check for invalid usage of different pointers in one expression.
> > +  if (ICmp->isEquality() && involvesMultiplePtrs(LHS, nullptr, L) &&
> > +      involvesMultiplePtrs(RHS, nullptr, L))
> > +    return false;
> > +
> > +  // Check for invalid usage of different pointers in a relational comparison.
> > +  if (ICmp->isRelational() && involvesMultiplePtrs(LHS, RHS, L))
> > +    return false;
> > +
> >    if (isAffine(LHS, L, Context) && isAffine(RHS, L, Context))
> >      return true;
> >
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits

-- 

Johannes Doerfert
Researcher / PhD Student

Compiler Design Lab (Prof. Hack)
Saarland Informatics Campus, Germany
Building E1.3, Room 4.31

Tel. +49 (0)681 302-57521 : doerfert at cs.uni-saarland.de
Fax. +49 (0)681 302-3065  : http://www.cdl.uni-saarland.de/people/doerfert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: Digital signature
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161206/e58f0b8d/attachment.sig>


More information about the llvm-commits mailing list