[Polly][PATCH 4/8] Allow the IslExprBuilder to compare pointers

Johannes Doerfert doerfert at cs.uni-saarland.de
Sun Aug 10 00:50:25 PDT 2014


---
 lib/CodeGen/IslExprBuilder.cpp | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/lib/CodeGen/IslExprBuilder.cpp b/lib/CodeGen/IslExprBuilder.cpp
index e78b4c0..b9bdabe 100644
--- a/lib/CodeGen/IslExprBuilder.cpp
+++ b/lib/CodeGen/IslExprBuilder.cpp
@@ -264,14 +264,20 @@ Value *IslExprBuilder::createOpICmp(__isl_take isl_ast_expr *Expr) {
   LHS = create(isl_ast_expr_get_op_arg(Expr, 0));
   RHS = create(isl_ast_expr_get_op_arg(Expr, 1));
 
-  Type *MaxType = LHS->getType();
-  MaxType = getWidestType(MaxType, RHS->getType());
+  bool IsPtrType = LHS->getType()->isPointerTy();
+  assert((!IsPtrType || RHS->getType()->isPointerTy()) &&
+         "Both ICmp operators should be pointer types or none of them");
 
-  if (MaxType != RHS->getType())
-    RHS = Builder.CreateSExt(RHS, MaxType);
+  if (!IsPtrType) {
+    Type *MaxType = LHS->getType();
+    MaxType = getWidestType(MaxType, RHS->getType());
 
-  if (MaxType != LHS->getType())
-    LHS = Builder.CreateSExt(LHS, MaxType);
+    if (MaxType != RHS->getType())
+      RHS = Builder.CreateSExt(RHS, MaxType);
+
+    if (MaxType != LHS->getType())
+      LHS = Builder.CreateSExt(LHS, MaxType);
+  }
 
   switch (isl_ast_expr_get_op_type(Expr)) {
   default:
@@ -280,16 +286,20 @@ Value *IslExprBuilder::createOpICmp(__isl_take isl_ast_expr *Expr) {
     Res = Builder.CreateICmpEQ(LHS, RHS);
     break;
   case isl_ast_op_le:
-    Res = Builder.CreateICmpSLE(LHS, RHS);
+    Res = IsPtrType ? Builder.CreateICmpULE(LHS, RHS)
+                    : Builder.CreateICmpSLE(LHS, RHS);
     break;
   case isl_ast_op_lt:
-    Res = Builder.CreateICmpSLT(LHS, RHS);
+    Res = IsPtrType ? Builder.CreateICmpULT(LHS, RHS)
+                    : Builder.CreateICmpSLT(LHS, RHS);
     break;
   case isl_ast_op_ge:
-    Res = Builder.CreateICmpSGE(LHS, RHS);
+    Res = IsPtrType ? Builder.CreateICmpUGE(LHS, RHS)
+                    : Builder.CreateICmpSGE(LHS, RHS);
     break;
   case isl_ast_op_gt:
-    Res = Builder.CreateICmpSGT(LHS, RHS);
+    Res = IsPtrType ? Builder.CreateICmpUGT(LHS, RHS)
+                    : Builder.CreateICmpSGT(LHS, RHS);
     break;
   }
 
-- 
2.0.4




More information about the llvm-commits mailing list