; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=indvars -S %s | FileCheck %s
%struct.A = type { i8 }
@c = global ptr null
@d = global i32 4
define void @_Z3fn1v() {
; CHECK-LABEL: @_Z3fn1v(
; CHECK-NEXT: [[X2:%.*]] = load i32, ptr @d, align 4
; CHECK-NEXT: [[X3:%.*]] = icmp slt i32 [[X2]], 1
; CHECK-NEXT: [[X4:%.*]] = select i1 [[X3]], i32 1, i32 [[X2]]
; CHECK-NEXT: [[X5:%.*]] = load ptr, ptr @c, align 8
; CHECK-NEXT: [[J_SROA_0_0_COPYLOAD:%.*]] = load i8, ptr [[X5]], align 1
; CHECK-NEXT: br label [[DOTPREHEADER4_LR_PH:%.*]]
; CHECK: .preheader4.lr.ph:
; CHECK-NEXT: [[TMP1:%.*]] = add nsw i32 [[X4]], -1
; CHECK-NEXT: [[TMP2:%.*]] = zext nneg i32 [[TMP1]] to i64
; CHECK-NEXT: [[TMP3:%.*]] = add nuw nsw i64 [[TMP2]], 1
; CHECK-NEXT: [[TMP4:%.*]] = sext i8 [[J_SROA_0_0_COPYLOAD]] to i64
; CHECK-NEXT: [[TMP5:%.*]] = mul i64 [[TMP3]], [[TMP4]]
; CHECK-NEXT: br label [[DOTPREHEADER4:%.*]]
; CHECK: .preheader4:
; CHECK-NEXT: [[K_09:%.*]] = phi ptr [ undef, [[DOTPREHEADER4_LR_PH]] ], [ [[X25:%.*]], [[X22:%.*]] ]
; CHECK-NEXT: [[X8:%.*]] = icmp ult i32 0, 4
; CHECK-NEXT: br i1 [[X8]], label [[DOTPREHEADER_LR_PH:%.*]], label [[X22]]
; CHECK: .preheader.lr.ph:
; CHECK-NEXT: br label [[DOTPREHEADER:%.*]]
; CHECK: .preheader:
; CHECK-NEXT: br label [[X17:%.*]]
; CHECK: x17:
; CHECK-NEXT: br i1 false, label [[DOTPREHEADER]], label [[DOT_CRIT_EDGE_8:%.*]]
; CHECK: ._crit_edge.8:
; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[K_09]], i64 [[TMP5]]
; CHECK-NEXT: br label [[X22]]
; CHECK: x22:
; CHECK-NEXT: [[K_1_LCSSA:%.*]] = phi ptr [ [[SCEVGEP]], [[DOT_CRIT_EDGE_8]] ], [ [[K_09]], [[DOTPREHEADER4]] ]
; CHECK-NEXT: [[X25]] = getelementptr i8, ptr [[K_1_LCSSA]]
; CHECK-NEXT: br label [[DOTPREHEADER4]]
;
%x2 = load i32, ptr @d
%x3 = icmp slt i32 %x2, 1
%x4 = select i1 %x3, i32 1, i32 %x2
%x5 = load ptr, ptr @c
%j.sroa.0.0.copyload = load i8, ptr %x5
br label %.preheader4.lr.ph
.preheader4.lr.ph: ; preds = %0
br label %.preheader4
.preheader4: ; preds = %x22, %.preheader4.lr.ph
%k.09 = phi ptr [ undef, %.preheader4.lr.ph ], [ %x25, %x22 ]
%x8 = icmp ult i32 0, 4
br i1 %x8, label %.preheader.lr.ph, label %x22
.preheader.lr.ph: ; preds = %.preheader4
br label %.preheader
.preheader: ; preds = %x17, %.preheader.lr.ph
%k.17 = phi ptr [ %k.09, %.preheader.lr.ph ], [ %x19, %x17 ]
%v.06 = phi i32 [ 0, %.preheader.lr.ph ], [ %x20, %x17 ]
br label %x17
x17: ; preds = %.preheader
%x18 = sext i8 %j.sroa.0.0.copyload to i64
%x19 = getelementptr i8, ptr %k.17, i64 %x18
%x20 = add i32 %v.06, 1
%x21 = icmp ult i32 %x20, %x4
br i1 %x21, label %.preheader, label %._crit_edge.8
._crit_edge.8: ; preds = %x17
%split = phi ptr [ %x19, %x17 ]
br label %x22
x22: ; preds = %._crit_edge.8, %.preheader4
%k.1.lcssa = phi ptr [ %split, %._crit_edge.8 ], [ %k.09, %.preheader4 ]
%x25 = getelementptr i8, ptr %k.1.lcssa
br label %.preheader4
}