[polly] r272486 - Recommit: "[FIX] Determine insertion point during SCEV expansion"

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 11 12:28:15 PDT 2016


Author: grosser
Date: Sat Jun 11 14:28:15 2016
New Revision: 272486

URL: http://llvm.org/viewvc/llvm-project?rev=272486&view=rev
Log:
Recommit: "[FIX] Determine insertion point during SCEV expansion"

This patch was originally contributed by Johannes Doerfert in r271892, but
was in conflict with the revert in r272483.

Added:
    polly/trunk/test/Isl/CodeGen/scop_expander_insert_point.ll
Modified:
    polly/trunk/lib/Support/ScopHelper.cpp

Modified: polly/trunk/lib/Support/ScopHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/ScopHelper.cpp?rev=272486&r1=272485&r2=272486&view=diff
==============================================================================
--- polly/trunk/lib/Support/ScopHelper.cpp (original)
+++ polly/trunk/lib/Support/ScopHelper.cpp Sat Jun 11 14:28:15 2016
@@ -280,11 +280,19 @@ private:
         return visit(NewE);
     }
 
-    Instruction *StartIP = R.getEnteringBlock()->getTerminator();
+    auto *EnteringBB = R.getEnteringBlock();
     Instruction *Inst = dyn_cast<Instruction>(E->getValue());
+    Instruction *IP;
+    if (Inst && !R.contains(Inst))
+      IP = Inst;
+    else if (Inst && EnteringBB->getParent() == Inst->getFunction())
+      IP = EnteringBB->getTerminator();
+    else
+      IP = EnteringBB->getParent()->getEntryBlock().getTerminator();
+
     if (!Inst || (Inst->getOpcode() != Instruction::SRem &&
                   Inst->getOpcode() != Instruction::SDiv))
-      return visitGenericInst(E, Inst, StartIP);
+      return visitGenericInst(E, Inst, IP);
 
     const SCEV *LHSScev = SE.getSCEV(Inst->getOperand(0));
     const SCEV *RHSScev = SE.getSCEV(Inst->getOperand(1));
@@ -292,11 +300,11 @@ private:
     if (!SE.isKnownNonZero(RHSScev))
       RHSScev = SE.getUMaxExpr(RHSScev, SE.getConstant(E->getType(), 1));
 
-    Value *LHS = expandCodeFor(LHSScev, E->getType(), StartIP);
-    Value *RHS = expandCodeFor(RHSScev, E->getType(), StartIP);
+    Value *LHS = expandCodeFor(LHSScev, E->getType(), IP);
+    Value *RHS = expandCodeFor(RHSScev, E->getType(), IP);
 
     Inst = BinaryOperator::Create((Instruction::BinaryOps)Inst->getOpcode(),
-                                  LHS, RHS, Inst->getName() + Name, StartIP);
+                                  LHS, RHS, Inst->getName() + Name, IP);
     return SE.getSCEV(Inst);
   }
 

Added: polly/trunk/test/Isl/CodeGen/scop_expander_insert_point.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/scop_expander_insert_point.ll?rev=272486&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/scop_expander_insert_point.ll (added)
+++ polly/trunk/test/Isl/CodeGen/scop_expander_insert_point.ll Sat Jun 11 14:28:15 2016
@@ -0,0 +1,43 @@
+; RUN: opt %loadPolly -polly-codegen -S < %s | FileCheck %s
+;
+; CHECK:      entry:
+; CHECK-NEXT:   %outvalue.141.phiops = alloca i64
+; CHECK-NEXT:   %.preload.s2a = alloca i8
+; CHECK-NEXT:   %divpolly = sdiv i32 undef, 1
+; CHECK-NEXT:   %div = sdiv i32 undef, undef
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+; Function Attrs: nounwind uwtable
+define void @int_downsample() #0 {
+entry:
+  %div = sdiv i32 undef, undef
+  br label %for.cond10.preheader.lr.ph
+
+for.cond10.preheader.lr.ph:                       ; preds = %entry
+  br label %for.body17.lr.ph
+
+for.body17.lr.ph:                                 ; preds = %for.end22, %for.cond10.preheader.lr.ph
+  %outcol_h.048 = phi i32 [ 0, %for.cond10.preheader.lr.ph ], [ %add31, %for.end22 ]
+  %0 = load i8*, i8** undef
+  %idx.ext = zext i32 %outcol_h.048 to i64
+  %add.ptr = getelementptr inbounds i8, i8* %0, i64 %idx.ext
+  br label %for.body17
+
+for.body17:                                       ; preds = %for.body17, %for.body17.lr.ph
+  %outvalue.141 = phi i64 [ undef, %for.body17.lr.ph ], [ %add19, %for.body17 ]
+  %inptr.040 = phi i8* [ %add.ptr, %for.body17.lr.ph ], [ undef, %for.body17 ]
+  %1 = load i8, i8* %inptr.040
+  %add19 = add nsw i64 0, %outvalue.141
+  br i1 false, label %for.body17, label %for.end22
+
+for.end22:                                        ; preds = %for.body17
+  %add31 = add i32 %outcol_h.048, %div
+  br i1 undef, label %for.body17.lr.ph, label %for.end32
+
+for.end32:                                        ; preds = %for.end22
+  br label %for.end36
+
+for.end36:                                        ; preds = %for.end32
+  ret void
+}




More information about the llvm-commits mailing list