; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=loop-idiom < %s -S | FileCheck %s
define void @f(ptr nocapture nonnull align 4 dereferenceable(20) %0, i32 %1) local_unnamed_addr #0 align 32 {
; CHECK-LABEL: @f(
; CHECK-NEXT: [[TMP3:%.*]] = trunc i32 [[TMP1:%.*]] to i2
; CHECK-NEXT: [[TMP4:%.*]] = zext i2 [[TMP3]] to i64
; CHECK-NEXT: [[TMP5:%.*]] = shl nuw nsw i64 [[TMP4]], 2
; CHECK-NEXT: [[UGLYGEP:%.*]] = getelementptr i8, ptr [[TMP0:%.*]], i64 [[TMP5]]
; CHECK-NEXT: [[TMP6:%.*]] = sub i2 -1, [[TMP3]]
; CHECK-NEXT: [[TMP7:%.*]] = zext i2 [[TMP6]] to i64
; CHECK-NEXT: [[TMP8:%.*]] = shl nuw nsw i64 [[TMP7]], 2
; CHECK-NEXT: [[TMP9:%.*]] = add nuw nsw i64 [[TMP8]], 4
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[UGLYGEP]], i8 0, i64 [[TMP9]], i1 false)
; CHECK-NEXT: br label [[TMP10:%.*]]
; CHECK: 10:
; CHECK-NEXT: [[TMP11:%.*]] = phi i32 [ [[TMP15:%.*]], [[TMP10]] ], [ [[TMP1]], [[TMP2:%.*]] ]
; CHECK-NEXT: [[TMP12:%.*]] = and i32 [[TMP11]], 3
; CHECK-NEXT: [[TMP13:%.*]] = zext i32 [[TMP12]] to i64
; CHECK-NEXT: [[TMP14:%.*]] = getelementptr inbounds i32, ptr [[TMP0]], i64 [[TMP13]]
; CHECK-NEXT: [[TMP15]] = add nsw i32 [[TMP11]], 1
; CHECK-NEXT: [[TMP16:%.*]] = and i32 [[TMP15]], 3
; CHECK-NEXT: [[TMP17:%.*]] = icmp eq i32 [[TMP16]], 0
; CHECK-NEXT: br i1 [[TMP17]], label [[TMP18:%.*]], label [[TMP10]]
; CHECK: 18:
; CHECK-NEXT: ret void
;
br label %3
3: ; preds = %3, %1
%4 = phi i32 [ %8, %3 ], [ %1, %2 ]
%5 = and i32 %4, 3
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds i32, ptr %0, i64 %6
store i32 0, ptr %7, align 4
%8 = add nsw i32 %4, 1
%9 = and i32 %8, 3
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %4
ret void
}