1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=loop-idiom -S %s | FileCheck %s
4 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-apple-macosx11.0.0"
7 ; Make sure the number of bytes is computed correctly in the presence of zero
8 ; extensions and preserved add flags.
9 define void @test(ptr %ptr) {
12 ; CHECK-NEXT: br label [[FOR_BODY_PREHEADER:%.*]]
14 ; CHECK-NEXT: br label [[FOR_BODY_PREHEADER]]
15 ; CHECK: for.body.preheader:
16 ; CHECK-NEXT: [[LIM_0:%.*]] = phi i32 [ 65, [[ENTRY:%.*]] ], [ 1, [[DEAD:%.*]] ]
17 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 8
18 ; CHECK-NEXT: [[UMAX:%.*]] = call i32 @llvm.umax.i32(i32 [[LIM_0]], i32 2)
19 ; CHECK-NEXT: [[TMP0:%.*]] = add nsw i32 [[UMAX]], -1
20 ; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
21 ; CHECK-NEXT: [[TMP2:%.*]] = shl nuw nsw i64 [[TMP1]], 3
22 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[SCEVGEP]], i8 0, i64 [[TMP2]], i1 false)
23 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
25 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[FOR_BODY]] ], [ 1, [[FOR_BODY_PREHEADER]] ]
26 ; CHECK-NEXT: [[IV_EXT:%.*]] = zext i32 [[IV]] to i64
27 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i64, ptr [[PTR]], i64 [[IV_EXT]]
28 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
29 ; CHECK-NEXT: [[CMP64:%.*]] = icmp ult i32 [[IV_NEXT]], [[LIM_0]]
30 ; CHECK-NEXT: br i1 [[CMP64]], label [[FOR_BODY]], label [[EXIT:%.*]]
32 ; CHECK-NEXT: ret void
35 br label %for.body.preheader
38 br label %for.body.preheader
41 %lim.0 = phi i32 [ 65, %entry ], [ 1, %dead ]
45 %iv = phi i32 [ %iv.next, %for.body ], [ 1, %for.body.preheader ]
46 %iv.ext = zext i32 %iv to i64
47 %gep = getelementptr inbounds i64, ptr %ptr, i64 %iv.ext
48 store i64 0, ptr %gep, align 8
49 %iv.next = add nuw nsw i32 %iv, 1
50 %cmp64 = icmp ult i32 %iv.next, %lim.0
51 br i1 %cmp64, label %for.body, label %exit