From: Johannes Doerfert Date: Thu, 29 Jan 2015 00:41:33 +0000 (+0000) Subject: [FIX] Handle pointer-pointer comparisons X-Git-Tag: llvmorg-3.7.0-rc1~13776 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ef61def9d57c10ad5efb38ce6e6bc5b9d3fcba72;p=platform%2Fupstream%2Fllvm.git [FIX] Handle pointer-pointer comparisons This should fix a problem introduced by r225464. llvm-svn: 227404 --- diff --git a/polly/lib/CodeGen/IslExprBuilder.cpp b/polly/lib/CodeGen/IslExprBuilder.cpp index 4dd7ba3..12096ea 100644 --- a/polly/lib/CodeGen/IslExprBuilder.cpp +++ b/polly/lib/CodeGen/IslExprBuilder.cpp @@ -175,9 +175,33 @@ Value *IslExprBuilder::createOpBin(__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 *LHSType = LHS->getType(); + Type *RHSType = RHS->getType(); - MaxType = LHS->getType(); - MaxType = getWidestType(MaxType, RHS->getType()); + // Handle +/- and +/- + 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. // diff --git a/polly/test/Isl/CodeGen/pointer-type-pointer-type-comparison.ll b/polly/test/Isl/CodeGen/pointer-type-pointer-type-comparison.ll new file mode 100644 index 0000000..32912e3 --- /dev/null +++ b/polly/test/Isl/CodeGen/pointer-type-pointer-type-comparison.ll @@ -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]]