[polly] r227404 - [FIX] Handle pointer-pointer comparisons
Johannes Doerfert
doerfert at cs.uni-saarland.de
Wed Jan 28 16:41:33 PST 2015
Author: jdoerfert
Date: Wed Jan 28 18:41:33 2015
New Revision: 227404
URL: http://llvm.org/viewvc/llvm-project?rev=227404&view=rev
Log:
[FIX] Handle pointer-pointer comparisons
This should fix a problem introduced by r225464.
Added:
polly/trunk/test/Isl/CodeGen/pointer-type-pointer-type-comparison.ll
Modified:
polly/trunk/lib/CodeGen/IslExprBuilder.cpp
Modified: polly/trunk/lib/CodeGen/IslExprBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslExprBuilder.cpp?rev=227404&r1=227403&r2=227404&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslExprBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/IslExprBuilder.cpp Wed Jan 28 18:41:33 2015
@@ -175,9 +175,33 @@ Value *IslExprBuilder::createOpBin(__isl
LHS = create(isl_ast_expr_get_op_arg(Expr, 0));
RHS = create(isl_ast_expr_get_op_arg(Expr, 1));
+ Type *LHSType = LHS->getType();
+ Type *RHSType = RHS->getType();
- MaxType = LHS->getType();
- MaxType = getWidestType(MaxType, RHS->getType());
+ // Handle <pointer> +/- <integer> and <integer> +/- <pointer>
+ if (LHSType->isPointerTy() || RHSType->isPointerTy()) {
+ isl_ast_expr_free(Expr);
+
+ assert((LHSType->isIntegerTy() || RHSType->isIntegerTy()) &&
+ "Arithmetic operations might only performed on one but not two "
+ "pointer types.");
+
+ if (LHSType->isIntegerTy())
+ std::swap(LHS, RHS);
+
+ switch (OpType) {
+ default:
+ llvm_unreachable(
+ "Only additive binary operations are allowed on pointer types.");
+ case isl_ast_op_sub:
+ RHS = Builder.CreateNeg(RHS);
+ // Fall through
+ case isl_ast_op_add:
+ return Builder.CreateGEP(LHS, RHS);
+ }
+ }
+
+ MaxType = getWidestType(LHSType, RHSType);
// Take the result into account when calculating the widest type.
//
Added: polly/trunk/test/Isl/CodeGen/pointer-type-pointer-type-comparison.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/pointer-type-pointer-type-comparison.ll?rev=227404&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/pointer-type-pointer-type-comparison.ll (added)
+++ polly/trunk/test/Isl/CodeGen/pointer-type-pointer-type-comparison.ll Wed Jan 28 18:41:33 2015
@@ -0,0 +1,47 @@
+; RUN: opt %loadPolly -polly-ast -analyze < %s | FileCheck %s
+; RUN: opt %loadPolly -polly-codegen-isl -S < %s | FileCheck %s -check-prefix=CODEGEN
+;
+; void f(int a[], int N, float *P, float *Q) {
+; int i;
+; for (i = 0; i < N; ++i)
+; if ((P + 1) != Q)
+; a[i] = i;
+; }
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @f(i64* nocapture %a, i64 %N, float * %P, float * %Q) nounwind {
+entry:
+ br label %bb
+
+bb:
+ %i = phi i64 [ 0, %entry ], [ %i.inc, %bb.backedge ]
+ %brcond = icmp ne float* %P, %Q
+ br i1 %brcond, label %store, label %bb.backedge
+
+store:
+ %scevgep = getelementptr i64* %a, i64 %i
+ store i64 %i, i64* %scevgep
+ br label %bb.backedge
+
+bb.backedge:
+ %i.inc = add nsw i64 %i, 1
+ %exitcond = icmp eq i64 %i.inc, %N
+ br i1 %exitcond, label %return, label %bb
+
+return:
+ ret void
+}
+
+; CHECK: if (Q >= P + 1) {
+; CHECK: for (int c0 = 0; c0 < N; c0 += 1)
+; CHECK: Stmt_store(c0);
+; CHECK: } else if (P >= Q + 1)
+; CHECK: for (int c0 = 0; c0 < N; c0 += 1)
+; CHECK: Stmt_store(c0);
+; CHECK: }
+
+; CODEGEN: %[[Pinc:[_a-zA-Z0-9]+]] = getelementptr float* %P, i64 1
+; CODEGEN-NEXT: icmp uge float* %Q, %[[Pinc]]
+; CODEGEN: %[[Qinc:[_a-zA-Z0-9]+]] = getelementptr float* %Q, i64 1
+; CODEGEN-NEXT: icmp uge float* %P, %[[Qinc]]
More information about the llvm-commits
mailing list