[polly] r322766 - [polly] [ScopInfo] Don't use isl_val_get_num_si.

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 17 13:59:02 PST 2018


Author: efriedma
Date: Wed Jan 17 13:59:02 2018
New Revision: 322766

URL: http://llvm.org/viewvc/llvm-project?rev=322766&view=rev
Log:
[polly] [ScopInfo] Don't use isl_val_get_num_si.

isl_val_get_num_si crashes on overflow, so don't use it on arbitrary
integers.

Testcase only crashes on platforms where long is 32 bits because of the
signature of isl_val_get_num_si; not sure if it's possible to write a
testcase which crashes if long is 64 bits.

There are a few other places in polly which use isl_val_get_num_si;
they probably need to be fixed as well. I don't think polly uses any
of the other "long" isl APIs in an unsafe manner.

Differential Revision: https://reviews.llvm.org/D42129


Modified:
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/test/ScopInfo/multidim_fold_constant_dim.ll

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=322766&r1=322765&r2=322766&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Wed Jan 17 13:59:02 2018
@@ -3428,9 +3428,13 @@ void Scop::foldSizeConstantsToRight() {
 
         int ValInt = 1;
 
-        if (isl_val_is_int(Val))
-          ValInt = isl_val_get_num_si(Val);
-        isl_val_free(Val);
+        if (isl_val_is_int(Val)) {
+          auto ValAPInt = APIntFromVal(Val);
+          if (ValAPInt.isSignedIntN(32))
+            ValInt = ValAPInt.getSExtValue();
+        } else {
+          isl_val_free(Val);
+        }
 
         Int.push_back(ValInt);
 

Modified: polly/trunk/test/ScopInfo/multidim_fold_constant_dim.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/multidim_fold_constant_dim.ll?rev=322766&r1=322765&r2=322766&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/multidim_fold_constant_dim.ll (original)
+++ polly/trunk/test/ScopInfo/multidim_fold_constant_dim.ll Wed Jan 17 13:59:02 2018
@@ -36,6 +36,7 @@ source_filename = "/tmp/test.c"
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 
 %struct.com = type { double, double }
+%struct.com2 = type { [20000000000 x double] }
 
 define void @foo(i64 %n, %struct.com* %A) {
 entry:
@@ -84,10 +85,39 @@ for.end9:
   ret void
 }
 
-define i32 @main() {
+; CHECK:      Arrays {
+; CHECK-NEXT:     double MemRef_O[*][%n]; // Element size 8
+; CHECK-NEXT: }
+
+define void @foo_overflow(i64 %n, %struct.com2* nocapture %O) local_unnamed_addr #0 {
 entry:
-  %A = alloca [100 x [1000 x %struct.com]], align 16
-  %tmp = getelementptr inbounds [100 x [1000 x %struct.com]], [100 x [1000 x %struct.com]]* %A, i64 0, i64 0, i64 0
-  call void @foo(i64 1000, %struct.com* nonnull %tmp)
-  ret i32 0
+  br label %for.body
+
+for.cond.cleanup:                                 ; preds = %for.cond.cleanup3
+  ret void
+
+for.body:                                         ; preds = %for.cond.cleanup3, %entry
+  %i.024 = phi i64 [ 0, %entry ], [ %inc12, %for.cond.cleanup3 ]
+  %0 = mul nsw i64 %i.024, %n
+  %arrayidx = getelementptr inbounds %struct.com2, %struct.com2* %O, i64 %0
+  br label %for.body4
+
+for.cond.cleanup3:                                ; preds = %for.body4
+  %inc12 = add nuw nsw i64 %i.024, 1
+  %exitcond25 = icmp eq i64 %inc12, 100
+  br i1 %exitcond25, label %for.cond.cleanup, label %for.body
+
+for.body4:                                        ; preds = %for.body4, %for.body
+  %j.023 = phi i64 [ 0, %for.body ], [ %inc, %for.body4 ]
+  %arrayidx5 = getelementptr inbounds %struct.com2, %struct.com2* %arrayidx, i64 %j.023
+  %Real = getelementptr inbounds %struct.com2, %struct.com2* %arrayidx5, i64 0, i32 0
+  %arrayidx6 = getelementptr inbounds [20000000000 x double], [20000000000 x double]* %Real, i64 0, i64 1
+  %1 = load double, double* %arrayidx6, align 8
+  %arrayidx10 = getelementptr inbounds [20000000000 x double], [20000000000 x double]* %Real, i64 0, i64 0
+  %2 = load double, double* %arrayidx10, align 8
+  %add = fadd double %1, %2
+  store double %add, double* %arrayidx10, align 8
+  %inc = add nuw nsw i64 %j.023, 1
+  %exitcond = icmp eq i64 %inc, 1000
+  br i1 %exitcond, label %for.cond.cleanup3, label %for.body4
 }




More information about the llvm-commits mailing list