[llvm] ec3efcf - [IVDescriptors] Skip FOR where we have multiple sink points for now.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 28 13:19:22 PST 2019


Author: Florian Hahn
Date: 2019-11-28T22:18:47+01:00
New Revision: ec3efcf11ff2fcdb5a754e3bda942dd5bef0928e

URL: https://github.com/llvm/llvm-project/commit/ec3efcf11ff2fcdb5a754e3bda942dd5bef0928e
DIFF: https://github.com/llvm/llvm-project/commit/ec3efcf11ff2fcdb5a754e3bda942dd5bef0928e.diff

LOG: [IVDescriptors] Skip FOR where we have multiple sink points for now.

This fixes a crash with instructions where multiple operands are
first-order-recurrences.

Added: 
    

Modified: 
    llvm/lib/Analysis/IVDescriptors.cpp
    llvm/test/Transforms/LoopVectorize/first-order-recurrence-complex.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index ce99226087fa..3c33aa973cdd 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -721,6 +721,13 @@ bool RecurrenceDescriptor::isFirstOrderRecurrence(
     if (I->getParent()->getTerminator() == I)
       return false;
 
+    // Do not try to sink an instruction multiple times (if multiple operands
+    // are first order recurrences).
+    // TODO: We can support this case, by sinking the instruction after the
+    // 'deepest' previous instruction.
+    if (SinkAfter.find(I) != SinkAfter.end())
+      return false;
+
     if (DT->dominates(Previous, I)) // We already are good w/o sinking.
       return true;
 

diff  --git a/llvm/test/Transforms/LoopVectorize/first-order-recurrence-complex.ll b/llvm/test/Transforms/LoopVectorize/first-order-recurrence-complex.ll
index e09804276ec8..aa913172f7b5 100644
--- a/llvm/test/Transforms/LoopVectorize/first-order-recurrence-complex.ll
+++ b/llvm/test/Transforms/LoopVectorize/first-order-recurrence-complex.ll
@@ -243,3 +243,33 @@ for:
 exit:
   ret void
 }
+
+; TODO: We should be able to sink %tmp38 after %tmp60.
+define void @instruction_with_2_FOR_operands() {
+; CHECK-LABEL: define void @instruction_with_2_FOR_operands(
+; CHECK-NEXT: bb:
+; CHECK-NEXT:   br label %bb13
+
+; CHECK-LABEL: bb13:
+; CHECK:         br i1 %tmp12, label %bb13, label %bb74
+
+; CHECK-LABEL: bb74:
+; CHECK-NEXT:    ret void
+;
+bb:
+  br label %bb13
+
+bb13:                                             ; preds = %bb13, %bb
+  %tmp37 = phi float [ %tmp60, %bb13 ], [ undef, %bb ]
+  %tmp27 = phi float [ %tmp49, %bb13 ], [ undef, %bb ]
+  %indvars.iv = phi i64 [ %indvars.iv.next, %bb13 ], [ 0, %bb ]
+  %tmp38 = fmul fast float %tmp37, %tmp27
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %tmp49 = load float, float* undef, align 4
+  %tmp60 = load float, float* undef, align 4
+  %tmp12 = icmp slt i64 %indvars.iv, undef
+  br i1 %tmp12, label %bb13, label %bb74
+
+bb74:                                             ; preds = %bb13
+  ret void
+}


        


More information about the llvm-commits mailing list