This reverts commit 4e545bdb355a470d601e9bb7f7b2693c99e61a3e. The newly added test is the third infinite combine loop caused by this change. In this case, it's a combination of the branch to common dest and jump threading folds that keeps peeling off loop iterations. The core problem here is that we ideally would not thread over loop backedges, both because it is potentially non-profitable (it may break canonical loop structure) and because it may result in these kinds of loops. Unfortunately, due to the lack of a dominator tree in SimplifyCFG, there is no good way to prevent this. While we have LoopHeaders, this is an optional structure and we don't do a good job of keeping it up to date. It would be fine for a profitability check, but is not suitable for a correctness check. So for now I'm just giving up here, as I don't see a good way to robustly prevent infinite combine loops. Fixes https://github.com/llvm/llvm-project/issues/56203.
64 lines
1.7 KiB
LLVM
64 lines
1.7 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt -S -simplifycfg < %s | FileCheck %s
|
|
|
|
; This used to infinitely thread between loop and loop.latch without reaching a
|
|
; fixed point.
|
|
|
|
declare void @dummy()
|
|
|
|
define i32 @main(i1 %c1, i1 %c2, i32 %y) {
|
|
; CHECK-LABEL: @main(
|
|
; CHECK-NEXT: br i1 [[C1:%.*]], label [[EXIT:%.*]], label [[LOOP_PRE_PREHEADER:%.*]]
|
|
; CHECK: loop.pre.preheader:
|
|
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[Y:%.*]], -1
|
|
; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_PREHEADER:%.*]], label [[EXIT]]
|
|
; CHECK: loop.preheader:
|
|
; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[Y]], 0
|
|
; CHECK-NEXT: br label [[LOOP:%.*]]
|
|
; CHECK: loop:
|
|
; CHECK-NEXT: br i1 [[C1]], label [[LOOP2:%.*]], label [[LOOP_LATCH:%.*]]
|
|
; CHECK: loop.latch:
|
|
; CHECK-NEXT: br i1 [[CMP]], label [[LOOP]], label [[EXIT]]
|
|
; CHECK: loop2:
|
|
; CHECK-NEXT: br i1 [[CMP2]], label [[JOIN:%.*]], label [[IF:%.*]]
|
|
; CHECK: if:
|
|
; CHECK-NEXT: call void @dummy()
|
|
; CHECK-NEXT: br label [[JOIN]]
|
|
; CHECK: join:
|
|
; CHECK-NEXT: br i1 [[C2:%.*]], label [[LOOP2]], label [[LOOP_LATCH]]
|
|
; CHECK: exit:
|
|
; CHECK-NEXT: ret i32 0
|
|
;
|
|
br i1 %c1, label %exit, label %loop.pre.preheader
|
|
|
|
loop.pre.preheader:
|
|
%cmp = icmp sgt i32 %y, -1
|
|
br i1 %cmp, label %loop.preheader, label %exit
|
|
|
|
loop.preheader:
|
|
%cmp2 = icmp eq i32 %y, 0
|
|
br label %loop
|
|
|
|
loop:
|
|
br i1 %c1, label %loop2, label %loop.latch
|
|
|
|
loop.latch:
|
|
br i1 %cmp, label %loop, label %exit
|
|
|
|
loop2:
|
|
br i1 %cmp2, label %join, label %if
|
|
|
|
if:
|
|
call void @dummy()
|
|
br label %join
|
|
|
|
join:
|
|
br i1 %c2, label %loop2, label %loop.latch
|
|
|
|
exit:
|
|
ret i32 0
|
|
|
|
; uselistorder directives
|
|
uselistorder label %loop2, { 1, 0 }
|
|
}
|