[llvm] e9d34c5 - [NFC] Add assert and test showing that revert of D109596 wasn't justified

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 19 22:01:30 PDT 2021


Author: Max Kazantsev
Date: 2021-09-20T12:01:12+07:00
New Revision: e9d34c54290e277e075aed33036fddae77b5f582

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

LOG: [NFC] Add assert and test showing that revert of D109596 wasn't justified

All transforms of IndVars have prerequisite requirement of LCSSA and LoopSimplify
form and rely on it. Added test that shows that this actually stands.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
    llvm/test/Transforms/IndVarSimplify/eliminate-backedge.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index 320e20ca341c..6d13b3b92560 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -1311,6 +1311,7 @@ static void foldExit(const Loop *L, BasicBlock *ExitingBB, bool IsTaken,
 
 static void replaceLoopPHINodesWithPreheaderValues(
     Loop *L, SmallVectorImpl<WeakTrackingVH> &DeadInsts) {
+  assert(L->isLoopSimplifyForm() && "Should only do it in simplify form!");
   auto *LoopPreheader = L->getLoopPreheader();
   auto *LoopHeader = L->getHeader();
   for (auto &PN : LoopHeader->phis()) {

diff  --git a/llvm/test/Transforms/IndVarSimplify/eliminate-backedge.ll b/llvm/test/Transforms/IndVarSimplify/eliminate-backedge.ll
index e2ba6e084dce..3fbf93da48f1 100644
--- a/llvm/test/Transforms/IndVarSimplify/eliminate-backedge.ll
+++ b/llvm/test/Transforms/IndVarSimplify/eliminate-backedge.ll
@@ -77,3 +77,88 @@ exit:
   [ %baz_ret, %latch ], [ 0, %entry ]
   ret i1 %val
 }
+
+define i1 @siblings(i8* align 1 %lhs, i8* align 1 %rhs, i32 %len) {
+; CHECK-LABEL: @siblings(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    %length_not_zero = icmp ne i32 %len, 0
+; CHECK-NEXT:    br i1 %length_not_zero, label %weird_loop.preheader, label %exit
+; CHECK:       weird_loop.preheader:
+; CHECK-NEXT:    br label %weird_loop
+; CHECK:       weird_loop:
+; CHECK-NEXT:    %weird.iv = phi i32 [ %weird.iv.next, %weird_loop ], [ 0, %weird_loop.preheader ]
+; CHECK-NEXT:    %weird.iv.next = add i32 %weird.iv, 1
+; CHECK-NEXT:    %weird.iv.wide = zext i32 %weird.iv to i64
+; CHECK-NEXT:    %weird.cond = call i1 @bar()
+; CHECK-NEXT:    br i1 %weird.cond, label %weird_loop, label %loop.preheader
+; CHECK:       loop.preheader:
+; CHECK-NEXT:    %weird.iv.lcssa = phi i32 [ %weird.iv, %weird_loop ]
+; CHECK-NEXT:    %weird.iv.wide.lcssa = phi i64 [ %weird.iv.wide, %weird_loop ]
+; CHECK-NEXT:    br label %loop
+; CHECK:       loop:
+; CHECK-NEXT:    %iv.next = add i32 %weird.iv.lcssa, 1
+; CHECK-NEXT:    %left_ptr = getelementptr inbounds i8, i8* %lhs, i32 %weird.iv.lcssa
+; CHECK-NEXT:    %right_ptr = getelementptr inbounds i8, i8* %rhs, i32 %weird.iv.lcssa
+; CHECK-NEXT:    %result = call i1 @foo(i8* %left_ptr, i8* %right_ptr)
+; CHECK-NEXT:    br i1 %result, label %exiting_1, label %exit.loopexit
+; CHECK:       exiting_1:
+; CHECK-NEXT:    %iv.wide.is_not_zero = icmp ne i64 %weird.iv.wide.lcssa, %weird.iv.wide.lcssa
+; CHECK-NEXT:    br i1 false, label %exiting_2, label %exit.loopexit
+; CHECK:       exiting_2:
+; CHECK-NEXT:    %bar_ret = call i1 @bar()
+; CHECK-NEXT:    br i1 %bar_ret, label %exit.loopexit, label %exiting_3
+; CHECK:       exiting_3:
+; CHECK-NEXT:    %baz_ret = call i1 @baz()
+; CHECK-NEXT:    %continue = icmp ne i32 %iv.next, %len
+; CHECK-NEXT:    %or.cond = select i1 %baz_ret, i1 %continue, i1 false
+; CHECK-NEXT:    br i1 %or.cond, label %loop, label %exit.loopexit
+; CHECK:       exit.loopexit:
+; CHECK-NEXT:    %val.ph = phi i1 [ %baz_ret, %exiting_3 ], [ %bar_ret, %exiting_2 ], [ %iv.wide.is_not_zero, %exiting_1 ], [ %result, %loop ]
+; CHECK-NEXT:    br label %exit
+; CHECK:       exit:
+; CHECK-NEXT:    %val = phi i1 [ false, %entry ], [ %val.ph, %exit.loopexit ]
+; CHECK-NEXT:    ret i1 %val
+;
+entry:
+  %length_not_zero = icmp ne i32 %len, 0
+  br i1 %length_not_zero, label %weird_loop, label %exit
+
+weird_loop:
+  %weird.iv = phi i32 [ 0, %entry ], [ %weird.iv.next, %weird_loop ]
+  %weird.iv.next = add i32 %weird.iv, 1
+  %weird.iv.wide = zext i32 %weird.iv to i64
+  %weird.cond = call i1 @bar()
+  br i1 %weird.cond, label %weird_loop, label %loop
+
+loop:
+  %iv = phi i32 [ %weird.iv, %weird_loop ], [ %iv.next, %latch ]
+  %iv.wide = phi i64 [ %weird.iv.wide, %weird_loop ], [ %iv.wide.next, %latch ]
+  %iv.next = add i32 %iv, 1
+  %iv.wide.next = add i64 %iv.wide, 1
+  %left_ptr = getelementptr inbounds i8, i8* %lhs, i32 %iv
+  %right_ptr = getelementptr inbounds i8, i8* %rhs, i32 %iv
+  %result = call i1 @foo(i8* %left_ptr, i8* %right_ptr)
+  br i1 %result, label %exiting_1, label %exit
+
+exiting_1:
+  %iv.wide.is_not_zero = icmp ne i64 %iv.wide, %weird.iv.wide
+  br i1 %iv.wide.is_not_zero, label %exiting_2, label %exit
+
+exiting_2:
+  %bar_ret = call i1 @bar()
+  br i1 %bar_ret, label %exit, label %exiting_3
+
+exiting_3:
+  %baz_ret = call i1 @baz()
+  br i1 %baz_ret, label %latch, label %exit
+
+latch:
+  %continue = icmp ne i32 %iv.next, %len
+  br i1 %continue, label %loop, label %exit
+
+exit:
+  %val = phi i1 [ %result, %loop ], [ %iv.wide.is_not_zero, %exiting_1 ],
+  [ %bar_ret, %exiting_2 ], [ %baz_ret, %exiting_3 ],
+  [ %baz_ret, %latch ], [ 0, %entry ]
+  ret i1 %val
+}


        


More information about the llvm-commits mailing list