[polly] r286430 - SCEVValidator: add new parameters resulting from constant extraction

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 9 22:45:29 PST 2016


Author: grosser
Date: Thu Nov 10 00:45:28 2016
New Revision: 286430

URL: http://llvm.org/viewvc/llvm-project?rev=286430&view=rev
Log:
SCEVValidator: add new parameters resulting from constant extraction

When extracting constant expressions out of SCEVs, new parameters may be
introduced, which have not been registered before. This change scans
SCEV expressions after constant extraction again to make sure newly
introduced parameters are registered.

We may for example extract the constant '8' from the expression '((8 * ((%a *
%b) + %c)) + (-8 * %a))' and obtain the expression '(((-1 + %b) * %a) + %c)'.
The new expression has a new parameter '(-1 + %b) * %a)', which was not
registered before, but must be registered to not crash.

This closes http://llvm.org/PR30953

Reported-by: Eli Friedman <efriedma at codeaurora.org>

Added:
    polly/trunk/test/ScopInfo/extract_constant_factor_introduces_new_parameter.ll
Modified:
    polly/trunk/lib/Support/SCEVAffinator.cpp

Modified: polly/trunk/lib/Support/SCEVAffinator.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/SCEVAffinator.cpp?rev=286430&r1=286429&r2=286430&view=diff
==============================================================================
--- polly/trunk/lib/Support/SCEVAffinator.cpp (original)
+++ polly/trunk/lib/Support/SCEVAffinator.cpp Thu Nov 10 00:45:28 2016
@@ -229,6 +229,9 @@ __isl_give PWACtx SCEVAffinator::visit(c
   auto *Factor = ConstantAndLeftOverPair.first;
   Expr = ConstantAndLeftOverPair.second;
 
+  auto *Scope = getScope();
+  S->addParams(getParamsInAffineExpr(&S->getRegion(), Scope, Expr, SE));
+
   // In case the scev is a valid parameter, we do not further analyze this
   // expression, but create a new parameter in the isl_pw_aff. This allows us
   // to treat subexpressions that we cannot translate into an piecewise affine

Added: polly/trunk/test/ScopInfo/extract_constant_factor_introduces_new_parameter.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/extract_constant_factor_introduces_new_parameter.ll?rev=286430&view=auto
==============================================================================
--- polly/trunk/test/ScopInfo/extract_constant_factor_introduces_new_parameter.ll (added)
+++ polly/trunk/test/ScopInfo/extract_constant_factor_introduces_new_parameter.ll Thu Nov 10 00:45:28 2016
@@ -0,0 +1,41 @@
+; RUN: opt %loadPolly -polly-detect -analyze < %s | FileCheck %s
+; RUN: opt %loadPolly -polly-scops -analyze < %s
+
+; CHECK: Valid Region for Scop: bb10 => bb16
+
+; Verify that -polly-scops does not crash. At some point this piece of
+; code crashed as we extracted from the SCEV expression:
+;
+;    ((8 * ((%a * %b) + %c)) + (-8 * %a))'
+;
+; the constant 8, which resulted in the new expression:
+;
+;    (((-1 + %b) * %a) + %c)
+;
+; which introduced a new parameter (-1 + %b) * %a which was not registered
+; correctly and consequently caused a crash due to an expression not being
+; regiustered as a parameter.
+
+target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
+
+define void @barney(i32* %arg, i32* %arg1, double* %arg2, i32* %arg3, i32 %a, i32 %b, i32 %c) {
+bb:
+  br label %bb10
+
+bb10:                                             ; preds = %bb
+  br i1 true, label %bb11, label %bb16
+
+bb11:                                             ; preds = %bb10
+  %tmp4 = add nsw i32 1, %a
+  %tmp5 = sub i32 0, %tmp4
+  %tmp8 = add nsw i32 %c, 1
+  %tmp12 = mul nsw i32 %b, %a
+  %tmp13 = add nsw i32 %tmp8, %tmp12
+  %tmp6 = getelementptr inbounds double, double* %arg2, i32 %tmp5
+  %tmp14 = getelementptr inbounds double, double* %tmp6, i32 %tmp13
+  %tmp15 = load double, double* %tmp14
+  br label %bb16
+
+bb16:                                             ; preds = %bb11, %bb10
+  unreachable
+}




More information about the llvm-commits mailing list