use the canonical IV only when it exists
authorSebastian Pop <spop@codeaurora.org>
Mon, 18 Mar 2013 19:09:49 +0000 (19:09 +0000)
committerSebastian Pop <spop@codeaurora.org>
Mon, 18 Mar 2013 19:09:49 +0000 (19:09 +0000)
llvm-svn: 177306

polly/lib/CodeGen/CodeGeneration.cpp
polly/lib/CodeGen/IslCodeGeneration.cpp

index ebe6e7e..f71e931 100644 (file)
@@ -370,24 +370,26 @@ void ClastStmtCodeGen::codegen(const clast_assignment *A, ScopStmt *Stmt,
                                unsigned Dim, int VectorDim,
                                std::vector<ValueMapT> *VectorVMap,
                                std::vector<LoopToScevMapT> *VLTS) {
-  const PHINode *PN;
   Value *RHS;
 
   assert(!A->LHS && "Statement assignments do not have left hand side");
 
-  PN = Stmt->getInductionVariableForDimension(Dim);
   RHS = ExpGen.codegen(A->RHS, Builder.getInt64Ty());
-  RHS = Builder.CreateTruncOrBitCast(RHS, PN->getType());
-
-  if (VectorVMap)
-    (*VectorVMap)[VectorDim][PN] = RHS;
 
   const llvm::SCEV *URHS = S->getSE()->getUnknown(RHS);
   if (VLTS)
     (*VLTS)[VectorDim][Stmt->getLoopForDimension(Dim)] = URHS;
-
-  ValueMap[PN] = RHS;
   LoopToScev[Stmt->getLoopForDimension(Dim)] = URHS;
+
+  const PHINode *PN = Stmt->getInductionVariableForDimension(Dim);
+  if (PN) {
+    RHS = Builder.CreateTruncOrBitCast(RHS, PN->getType());
+
+    if (VectorVMap)
+      (*VectorVMap)[VectorDim][PN] = RHS;
+
+    ValueMap[PN] = RHS;
+  }
 }
 
 void ClastStmtCodeGen::codegenSubstitutions(
index 398408f..721596a 100644 (file)
@@ -891,21 +891,23 @@ void IslNodeBuilder::createSubstitutions(
   for (unsigned i = 0; i < isl_pw_multi_aff_dim(PMA, isl_dim_out); ++i) {
     isl_pw_aff *Aff;
     isl_ast_expr *Expr;
-    const Value *OldIV;
     Value *V;
 
     Aff = isl_pw_multi_aff_get_pw_aff(PMA, i);
     Expr = isl_ast_build_expr_from_pw_aff(Context, Aff);
-    OldIV = Stmt->getInductionVariableForDimension(i);
     V = ExprBuilder.create(Expr);
 
+    ScalarEvolution *SE = Stmt->getParent()->getSE();
+    LTS[Stmt->getLoopForDimension(i)] = SE->getUnknown(V);
+
     // CreateIntCast can introduce trunc expressions. This is correct, as the
     // result will always fit into the type of the original induction variable
     // (because we calculate a value of the original induction variable).
-    V = Builder.CreateIntCast(V, OldIV->getType(), true);
-    VMap[OldIV] = V;
-    ScalarEvolution *SE = Stmt->getParent()->getSE();
-    LTS[Stmt->getLoopForDimension(i)] = SE->getUnknown(V);
+    const Value *OldIV = Stmt->getInductionVariableForDimension(i);
+    if (OldIV) {
+      V = Builder.CreateIntCast(V, OldIV->getType(), true);
+      VMap[OldIV] = V;
+    }
   }
 
   isl_pw_multi_aff_free(PMA);