[polly] r360238 - [polly][SCEV] Expand SCEV matcher cases for new smin/umin ops

Keno Fischer via llvm-commits llvm-commits at lists.llvm.org
Wed May 8 03:36:04 PDT 2019


Author: kfischer
Date: Wed May  8 03:36:04 2019
New Revision: 360238

URL: http://llvm.org/viewvc/llvm-project?rev=360238&view=rev
Log:
[polly][SCEV] Expand SCEV matcher cases for new smin/umin ops

These were added in rL360159, but I neglected to update polly at the
same time.

Modified:
    polly/trunk/include/polly/Support/SCEVAffinator.h
    polly/trunk/lib/Support/SCEVAffinator.cpp
    polly/trunk/lib/Support/SCEVValidator.cpp
    polly/trunk/lib/Support/ScopHelper.cpp
    polly/trunk/test/ScopInfo/smax.ll

Modified: polly/trunk/include/polly/Support/SCEVAffinator.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/Support/SCEVAffinator.h?rev=360238&r1=360237&r2=360238&view=diff
==============================================================================
--- polly/trunk/include/polly/Support/SCEVAffinator.h (original)
+++ polly/trunk/include/polly/Support/SCEVAffinator.h Wed May  8 03:36:04 2019
@@ -103,7 +103,9 @@ private:
   PWACtx visitUDivExpr(const llvm::SCEVUDivExpr *E);
   PWACtx visitAddRecExpr(const llvm::SCEVAddRecExpr *E);
   PWACtx visitSMaxExpr(const llvm::SCEVSMaxExpr *E);
+  PWACtx visitSMinExpr(const llvm::SCEVSMinExpr *E);
   PWACtx visitUMaxExpr(const llvm::SCEVUMaxExpr *E);
+  PWACtx visitUMinExpr(const llvm::SCEVUMinExpr *E);
   PWACtx visitUnknown(const llvm::SCEVUnknown *E);
   PWACtx visitSDivInstruction(llvm::Instruction *SDiv);
   PWACtx visitSRemInstruction(llvm::Instruction *SRem);

Modified: polly/trunk/lib/Support/SCEVAffinator.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/SCEVAffinator.cpp?rev=360238&r1=360237&r2=360238&view=diff
==============================================================================
--- polly/trunk/lib/Support/SCEVAffinator.cpp (original)
+++ polly/trunk/lib/Support/SCEVAffinator.cpp Wed May  8 03:36:04 2019
@@ -435,10 +435,26 @@ PWACtx SCEVAffinator::visitSMaxExpr(cons
   return Max;
 }
 
+PWACtx SCEVAffinator::visitSMinExpr(const SCEVSMinExpr *Expr) {
+  PWACtx Min = visit(Expr->getOperand(0));
+
+  for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
+    Min = combine(Min, visit(Expr->getOperand(i)), isl_pw_aff_min);
+    if (isTooComplex(Min))
+      return complexityBailout();
+  }
+
+  return Min;
+}
+
 PWACtx SCEVAffinator::visitUMaxExpr(const SCEVUMaxExpr *Expr) {
   llvm_unreachable("SCEVUMaxExpr not yet supported");
 }
 
+PWACtx SCEVAffinator::visitUMinExpr(const SCEVUMinExpr *Expr) {
+  llvm_unreachable("SCEVUMinExpr not yet supported");
+}
+
 PWACtx SCEVAffinator::visitUDivExpr(const SCEVUDivExpr *Expr) {
   // The handling of unsigned division is basically the same as for signed
   // division, except the interpretation of the operands. As the divisor

Modified: polly/trunk/lib/Support/SCEVValidator.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/SCEVValidator.cpp?rev=360238&r1=360237&r2=360238&view=diff
==============================================================================
--- polly/trunk/lib/Support/SCEVValidator.cpp (original)
+++ polly/trunk/lib/Support/SCEVValidator.cpp Wed May  8 03:36:04 2019
@@ -294,6 +294,21 @@ public:
     return Return;
   }
 
+  class ValidatorResult visitSMinExpr(const SCEVSMinExpr *Expr) {
+    ValidatorResult Return(SCEVType::INT);
+
+    for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) {
+      ValidatorResult Op = visit(Expr->getOperand(i));
+
+      if (!Op.isValid())
+        return Op;
+
+      Return.merge(Op);
+    }
+
+    return Return;
+  }
+
   class ValidatorResult visitUMaxExpr(const SCEVUMaxExpr *Expr) {
     // We do not support unsigned max operations. If 'Expr' is constant during
     // Scop execution we treat this as a parameter, otherwise we bail out.
@@ -305,6 +320,21 @@ public:
         return ValidatorResult(SCEVType::INVALID);
       }
     }
+
+    return ValidatorResult(SCEVType::PARAM, Expr);
+  }
+
+  class ValidatorResult visitUMinExpr(const SCEVUMinExpr *Expr) {
+    // We do not support unsigned min operations. If 'Expr' is constant during
+    // Scop execution we treat this as a parameter, otherwise we bail out.
+    for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) {
+      ValidatorResult Op = visit(Expr->getOperand(i));
+
+      if (!Op.isConstant()) {
+        LLVM_DEBUG(dbgs() << "INVALID: UMinExpr has a non-constant operand");
+        return ValidatorResult(SCEVType::INVALID);
+      }
+    }
 
     return ValidatorResult(SCEVType::PARAM, Expr);
   }

Modified: polly/trunk/lib/Support/ScopHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/ScopHelper.cpp?rev=360238&r1=360237&r2=360238&view=diff
==============================================================================
--- polly/trunk/lib/Support/ScopHelper.cpp (original)
+++ polly/trunk/lib/Support/ScopHelper.cpp Wed May  8 03:36:04 2019
@@ -370,6 +370,18 @@ private:
       NewOps.push_back(visit(Op));
     return SE.getSMaxExpr(NewOps);
   }
+  const SCEV *visitUMinExpr(const SCEVUMinExpr *E) {
+    SmallVector<const SCEV *, 4> NewOps;
+    for (const SCEV *Op : E->operands())
+      NewOps.push_back(visit(Op));
+    return SE.getUMinExpr(NewOps);
+  }
+  const SCEV *visitSMinExpr(const SCEVSMinExpr *E) {
+    SmallVector<const SCEV *, 4> NewOps;
+    for (const SCEV *Op : E->operands())
+      NewOps.push_back(visit(Op));
+    return SE.getSMinExpr(NewOps);
+  }
   const SCEV *visitAddRecExpr(const SCEVAddRecExpr *E) {
     SmallVector<const SCEV *, 4> NewOps;
     for (const SCEV *Op : E->operands())

Modified: polly/trunk/test/ScopInfo/smax.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/smax.ll?rev=360238&r1=360237&r2=360238&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/smax.ll (original)
+++ polly/trunk/test/ScopInfo/smax.ll Wed May  8 03:36:04 2019
@@ -22,4 +22,4 @@ for.end:
 
 ; We check that there are only two parameters, but not a third one that
 ; represents the smax() expression. This test case comes from PR 18155.
-; CHECK: [w, x_pos]
+; CHECK: [x_pos, w]




More information about the llvm-commits mailing list