diff mbox

[GSoC] Elimination of CLooG library installation dependency

Message ID CABGF_gei3Mzg2sAgxmHBeObLsGF6oV-UpzPDsmMpz8mBSEx90Q@mail.gmail.com
State New
Headers show

Commit Message

Roman Gareev Aug. 11, 2014, 7:11 a.m. UTC
> I am confused. It seems you attached some kind of reduced version of
> btCollisionWorld.cpp? How did you obtain it? Did you compile and test
> with these versions?

I’ve manually selected parts of code, which produce the scope.

I’ve found out that this bug is most probably caused by absence of
pointer handling.  The tree, which is corresponding to P_11 has
pointer type. Furthermore,  if we consider the transformed gimple code
for (it can be found attached), we’ll see that it contains wrong
parts:

The code produced by modified version of Graphite:
...
      _35 = (signed long) _11;
      _36 = _34 + _35;
      _37 = _36 % 0;
      _38 = _37 > 0;
      _39 = (signed long) _38;
...

The code produced by origin version of Graphite:

...
      _36 = (sizetype) _11;
      _37 = _36 + 18446744073709551615;
      _38 = 8B + _37;
      _39 = _38 % 0B;
      _40 = _39 != -1B;
...

(If I’m not mistaken, 0B, for example, corresponds to (void *).  It
can be seen here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50712)

I’ve tried to implement pointer handling in the attached patch, but it
is wrong. I get the following error instead of seagfault now:

Floating point exception (core dumped)

back trace:

Program terminated with signal 8, Arithmetic exception.
#0  0x00000000004204c5 in allocSize (this=<optimized out>,
    size=<optimized out>)
    at /home/roman/llvm-test-suite/MultiSource/Benchmarks/Bullet/include/LinearMath/btAlignedObjectArray.h:59
59 return (size ? size*2 : 1);
(gdb) bt
#0  0x00000000004204c5 in allocSize (this=<optimized out>,
    size=<optimized out>)
    at /home/roman/llvm-test-suite/MultiSource/Benchmarks/Bullet/include/LinearMath/btAlignedObjectArray.h:59
#1  push_back (_Val=<synthetic pointer>, this=0x1125600)
    at /home/roman/llvm-test-suite/MultiSource/Benchmarks/Bullet/include/LinearMath/btAlignedObjectArray.h:220
#2  btCollisionDispatcher::getNewManifold (this=0x11255f0, b0=<optimized out>,
    b1=<optimized out>) at btCollisionDispatcher.llvm.cpp:100
#3  0x000000000044e764 in
btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm
(this=0x7f665ca6b0c0, mf=0x0, ci=..., col0=<optimized out>,
    col1=<optimized out>, isSwapped=<optimized out>,
    numPerturbationIterations=1, minimumPointsPerturbationThreshold=1)
    at /home/roman/llvm-test-suite/MultiSource/Benchmarks/Bullet/btConvexPlaneCollisionAlgorithm.cpp:38
#4  0x000000000046281b in
btConvexPlaneCollisionAlgorithm::CreateFunc::CreateCollisionAlgorithm
(this=0x11254e0, ci=..., body0=0x113d040, body1=0x113d810)
    at /home/roman/llvm-test-suite/MultiSource/Benchmarks/Bullet/include/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h:76
#5  0x00000000004205ac in btCollisionDispatcher::findAlgorithm (
    this=<optimized out>, body0=<optimized out>, body1=<optimized out>,
    sharedManifold=<optimized out>) at btCollisionDispatcher.llvm.cpp:145
#6  0x00000000004202e2 in btCollisionDispatcher::defaultNearCallback (
---Type <return> to continue, or q <return> to quit---
    collisionPair=..., dispatcher=..., dispatchInfo=...)
    at btCollisionDispatcher.llvm.cpp:258
#7  0x000000000042083b in btCollisionPairCallback::processOverlap (
    this=<optimized out>, pair=...) at btCollisionDispatcher.llvm.cpp:224
#8  0x00000000004acff2 in
btHashedOverlappingPairCache::processAllOverlappingPairs
(this=0x1127f80, callback=0x7fff0d1af790, dispatcher=0x11255f0)
    at /home/roman/llvm-test-suite/MultiSource/Benchmarks/Bullet/btOverlappingPairCache.cpp:387
#9  0x00000000004200c9 in btCollisionDispatcher::dispatchAllCollisionPairs (
    this=<optimized out>, pairCache=<optimized out>, dispatchInfo=...,
    dispatcher=<optimized out>) at btCollisionDispatcher.llvm.cpp:238
#10 0x0000000000421bd4 in btCollisionWorld::performDiscreteCollisionDetection()
    ()
#11 0x0000000000464d9a in
btDiscreteDynamicsWorld::internalSingleStepSimulation(float) ()
#12 0x000000000046473f in
btDiscreteDynamicsWorld::stepSimulation(float, int, float) ()
#13 0x0000000000401e08 in BenchmarkDemo::clientMoveAndDisplay (
    this=0x7fff0d1af980)
    at /home/roman/llvm-test-suite/MultiSource/Benchmarks/Bullet/BenchmarkDemo.cpp:232
#14 0x0000000000401b12 in main (argc=<optimized out>, argv=<optimized out>)
    at /home/roman/llvm-test-suite/MultiSource/Benchmarks/Bullet/main.cpp:63

Could you please advise me an algorithm for pointer handling?

Comments

Tobias Grosser Aug. 11, 2014, 7:27 a.m. UTC | #1
On 11/08/2014 09:11, Roman Gareev wrote:
>> I am confused. It seems you attached some kind of reduced version of
>> btCollisionWorld.cpp? How did you obtain it? Did you compile and test
>> with these versions?
>
> I’ve manually selected parts of code, which produce the scope.
>
> I’ve found out that this bug is most probably caused by absence of
> pointer handling.  The tree, which is corresponding to P_11 has
> pointer type. Furthermore,  if we consider the transformed gimple code
> for (it can be found attached), we’ll see that it contains wrong
> parts:
>
>
> Could you please advise me an algorithm for pointer handling?

Did you try your code with 64bit pointer types?

In any case, I don't think it is worth spending time on this. I would 
check in the scop detection that we disable the handling of unsigned and 
pointer types. It is a complex thing to model and the approach currently 
taking of always model their wrapping behaviour seems wrong.
What we should do later is to build a run-time check that ensures
no pointer overflow is happening and then just create code without it.

Cheers,
Tobias
diff mbox

Patch

Index: gcc/graphite-isl-ast-to-gimple.c
===================================================================
--- gcc/graphite-isl-ast-to-gimple.c	(revision 213774)
+++ gcc/graphite-isl-ast-to-gimple.c	(working copy)
@@ -150,6 +150,8 @@ 
   gcc_assert (res != ip.end () &&
               "Could not map isl_id to tree expression");
   isl_ast_expr_free (expr_id);
+  if (POINTER_TYPE_P (TREE_TYPE (res->second)))
+    return res->second;
   return fold_convert (type, res->second);
 }
 
@@ -178,18 +180,46 @@ 
    type TYPE.  */
 
 static tree
-binary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, ivs_params &ip)
+binary_op_to_tree (tree recommended_type, __isl_take isl_ast_expr *expr,
+		   ivs_params &ip)
 {
   isl_ast_expr *arg_expr = isl_ast_expr_get_op_arg (expr, 0);
-  tree tree_lhs_expr = gcc_expression_from_isl_expression (type, arg_expr, ip);
+  tree tree_lhs_expr =
+    gcc_expression_from_isl_expression (recommended_type, arg_expr, ip);
   arg_expr = isl_ast_expr_get_op_arg (expr, 1);
-  tree tree_rhs_expr = gcc_expression_from_isl_expression (type, arg_expr, ip);
+  tree tree_rhs_expr =
+    gcc_expression_from_isl_expression (recommended_type, arg_expr, ip);
+  tree type = POINTER_TYPE_P (TREE_TYPE (tree_lhs_expr)) ?
+	      TREE_TYPE (tree_lhs_expr) : recommended_type;
+  type = POINTER_TYPE_P (TREE_TYPE (tree_rhs_expr)) ?
+	 TREE_TYPE (tree_rhs_expr) : type;
+  if (POINTER_TYPE_P (type))
+    {
+      if (isl_ast_expr_get_op_type (expr) == isl_ast_op_add ||
+	  isl_ast_expr_get_op_type (expr) == isl_ast_op_mul ||
+	  isl_ast_expr_get_op_type (expr) == isl_ast_op_div)
+        {
+          if (!POINTER_TYPE_P (TREE_TYPE (tree_lhs_expr)))
+            tree_lhs_expr = fold_convert (sizetype, tree_lhs_expr);
+          if (!POINTER_TYPE_P (TREE_TYPE (tree_rhs_expr)))
+            tree_rhs_expr = fold_convert (sizetype, tree_rhs_expr);
+        }
+      else
+        {
+          tree_lhs_expr = fold_convert (type, tree_lhs_expr);
+          tree_rhs_expr = fold_convert (type, tree_rhs_expr);
+        }
+    }
   enum isl_ast_op_type expr_type = isl_ast_expr_get_op_type (expr);
   isl_ast_expr_free (expr);
   switch (expr_type)
     {
     case isl_ast_op_add:
-      return fold_build2 (PLUS_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+      if (POINTER_TYPE_P (type))
+        return fold_build2 (POINTER_PLUS_EXPR, type, tree_lhs_expr,
+			    tree_rhs_expr);
+      else
+        return fold_build2 (PLUS_EXPR, type, tree_lhs_expr, tree_rhs_expr);
 
     case isl_ast_op_sub:
       return fold_build2 (MINUS_EXPR, type, tree_lhs_expr, tree_rhs_expr);
@@ -210,26 +240,32 @@ 
       return fold_build2 (FLOOR_DIV_EXPR, type, tree_lhs_expr, tree_rhs_expr);
 
     case isl_ast_op_and:
-      return fold_build2 (TRUTH_ANDIF_EXPR, type,
+      return fold_build2 (TRUTH_ANDIF_EXPR, boolean_type_node,
 			  tree_lhs_expr, tree_rhs_expr);
 
     case isl_ast_op_or:
-      return fold_build2 (TRUTH_ORIF_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+      return fold_build2 (TRUTH_ORIF_EXPR, boolean_type_node, tree_lhs_expr,
+			  tree_rhs_expr);
 
     case isl_ast_op_eq:
-      return fold_build2 (EQ_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+      return fold_build2 (EQ_EXPR, boolean_type_node, tree_lhs_expr,
+			  tree_rhs_expr);
 
     case isl_ast_op_le:
-      return fold_build2 (LE_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+      return fold_build2 (LE_EXPR, boolean_type_node, tree_lhs_expr,
+			  tree_rhs_expr);
 
     case isl_ast_op_lt:
-      return fold_build2 (LT_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+      return fold_build2 (LT_EXPR, boolean_type_node, tree_lhs_expr,
+			  tree_rhs_expr);
 
     case isl_ast_op_ge:
-      return fold_build2 (GE_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+      return fold_build2 (GE_EXPR, boolean_type_node, tree_lhs_expr,
+			  tree_rhs_expr);
 
     case isl_ast_op_gt:
-      return fold_build2 (GT_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+      return fold_build2 (GT_EXPR, boolean_type_node, tree_lhs_expr,
+			  tree_rhs_expr);
 
     default:
       gcc_unreachable ();
@@ -261,12 +297,16 @@ 
    type TYPE.  */
 
 static tree
-unary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, ivs_params &ip)
+unary_op_to_tree (tree recommended_type, __isl_take isl_ast_expr *expr,
+		  ivs_params &ip)
 {
   gcc_assert (isl_ast_expr_get_op_type (expr) == isl_ast_op_minus);
   isl_ast_expr *arg_expr = isl_ast_expr_get_op_arg (expr, 0);
-  tree tree_expr = gcc_expression_from_isl_expression (type, arg_expr, ip);
+  tree tree_expr =
+    gcc_expression_from_isl_expression (recommended_type, arg_expr, ip);
   isl_ast_expr_free (expr);
+  tree type = POINTER_TYPE_P (TREE_TYPE (tree_expr)) ?
+	      TREE_TYPE (tree_expr) : recommended_type;
   return fold_build1 (NEGATE_EXPR, type, tree_expr);
 }