1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -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(i64* %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 i64, i64* [[PTR:%.*]], i64 1
18 ; CHECK-NEXT: [[SCEVGEP1:%.*]] = bitcast i64* [[SCEVGEP]] to i8*
19 ; CHECK-NEXT: [[UMAX:%.*]] = call i32 @llvm.umax.i32(i32 [[LIM_0]], i32 2)
20 ; CHECK-NEXT: [[TMP0:%.*]] = add nsw i32 [[UMAX]], -1
21 ; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
22 ; CHECK-NEXT: [[TMP2:%.*]] = shl nuw nsw i64 [[TMP1]], 3
23 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 8 [[SCEVGEP1]], i8 0, i64 [[TMP2]], i1 false)
24 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
26 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[FOR_BODY]] ], [ 1, [[FOR_BODY_PREHEADER]] ]
27 ; CHECK-NEXT: [[IV_EXT:%.*]] = zext i32 [[IV]] to i64
28 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i64, i64* [[PTR]], i64 [[IV_EXT]]
29 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
30 ; CHECK-NEXT: [[CMP64:%.*]] = icmp ult i32 [[IV_NEXT]], [[LIM_0]]
31 ; CHECK-NEXT: br i1 [[CMP64]], label [[FOR_BODY]], label [[EXIT:%.*]]
33 ; CHECK-NEXT: ret void
36 br label %for.body.preheader
39 br label %for.body.preheader
42 %lim.0 = phi i32 [ 65, %entry ], [ 1, %dead ]
46 %iv = phi i32 [ %iv.next, %for.body ], [ 1, %for.body.preheader ]
47 %iv.ext = zext i32 %iv to i64
48 %gep = getelementptr inbounds i64, i64* %ptr, i64 %iv.ext
49 store i64 0, i64* %gep, align 8
50 %iv.next = add nuw nsw i32 %iv, 1
51 %cmp64 = icmp ult i32 %iv.next, %lim.0
52 br i1 %cmp64, label %for.body, label %exit