llvm/llvm/test/Transforms/LoopPredication/pr66382.ll

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
; RUN: opt -S -loop-predication-skip-profitability-checks=false -passes='require<scalar-evolution>,loop-mssa(loop-predication)' %s | FileCheck %s

target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nocallback nofree nosync willreturn
declare void @llvm.experimental.guard(i1, ...) #0

; Check that LoopPredication doesn't crash on all-zero branch weights
define void @foo() {
; CHECK-LABEL: define void @foo() {
; CHECK-NEXT:  entry:
; CHECK-NEXT:    br label [[HEADER:%.*]]
; CHECK:       Header:
; CHECK-NEXT:    [[J2:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[J_NEXT:%.*]], [[LATCH:%.*]] ]
; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 false, i32 0) [ "deopt"() ]
; CHECK-NEXT:    [[J_NEXT]] = add i64 [[J2]], 1
; CHECK-NEXT:    br i1 false, label [[LATCH]], label [[EXIT:%.*]]
; CHECK:       Latch:
; CHECK-NEXT:    [[SPECULATE_TRIP_COUNT:%.*]] = icmp ult i64 [[J2]], 0
; CHECK-NEXT:    br i1 [[SPECULATE_TRIP_COUNT]], label [[HEADER]], label [[COMMON_RET_LOOPEXIT:%.*]], !prof [[PROF0:![0-9]+]]
; CHECK:       common.ret.loopexit:
; CHECK-NEXT:    br label [[COMMON_RET:%.*]]
; CHECK:       common.ret:
; CHECK-NEXT:    ret void
; CHECK:       exit:
; CHECK-NEXT:    br label [[COMMON_RET]]
;
entry:
  br label %Header

Header:                                           ; preds = %Latch, %entry
  %j2 = phi i64 [ 0, %entry ], [ %j.next, %Latch ]
  call void (i1, ...) @llvm.experimental.guard(i1 false, i32 0) [ "deopt"() ]
  %j.next = add i64 %j2, 1
  br i1 false, label %Latch, label %exit

Latch:                                            ; preds = %Header
  %speculate_trip_count = icmp ult i64 %j2, 0
  br i1 %speculate_trip_count, label %Header, label %common.ret, !prof !0

common.ret:                                       ; preds = %exit, %Latch
  ret void

exit:                                             ; preds = %Header
  br label %common.ret
}

attributes #0 = { nocallback nofree nosync willreturn }

!0 = !{!"branch_weights", i32 0, i32 0}