1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -O2 < %s | FileCheck %s
4 ; Test a single-iteration loop that should get SROAd once we realize that fact.
5 ; It should compile down to a bswap.
7 ; The helper function exists to avoid IPSCCP breaking the loop too early.
9 define i16 @helper(i16 %0, i64 %x) {
10 ; CHECK-LABEL: @helper(
12 ; CHECK-NEXT: [[DATA:%.*]] = alloca [2 x i8], align 2
13 ; CHECK-NEXT: store i16 [[TMP0:%.*]], ptr [[DATA]], align 2
14 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[DATA]], i64 1
15 ; CHECK-NEXT: br label [[BB6_I_I:%.*]]
17 ; CHECK-NEXT: [[ITER_SROA_0_07_I_I:%.*]] = phi i64 [ [[TMP2:%.*]], [[BB6_I_I]] ], [ 0, [[START:%.*]] ]
18 ; CHECK-NEXT: [[_40_I_I:%.*]] = sub nsw i64 0, [[ITER_SROA_0_07_I_I]]
19 ; CHECK-NEXT: [[TMP2]] = add nuw nsw i64 [[ITER_SROA_0_07_I_I]], 1
20 ; CHECK-NEXT: [[_34_I_I:%.*]] = getelementptr inbounds [0 x i8], ptr [[DATA]], i64 0, i64 [[ITER_SROA_0_07_I_I]]
21 ; CHECK-NEXT: [[_39_I_I:%.*]] = getelementptr inbounds [0 x i8], ptr [[TMP1]], i64 0, i64 [[_40_I_I]]
22 ; CHECK-NEXT: [[TMP_0_COPYLOAD_I_I_I_I:%.*]] = load i8, ptr [[_34_I_I]], align 1
23 ; CHECK-NEXT: [[TMP2_0_COPYLOAD_I_I_I_I:%.*]] = load i8, ptr [[_39_I_I]], align 1
24 ; CHECK-NEXT: store i8 [[TMP2_0_COPYLOAD_I_I_I_I]], ptr [[_34_I_I]], align 1
25 ; CHECK-NEXT: store i8 [[TMP_0_COPYLOAD_I_I_I_I]], ptr [[_39_I_I]], align 1
26 ; CHECK-NEXT: [[EXITCOND_NOT_I_I:%.*]] = icmp eq i64 [[TMP2]], [[X:%.*]]
27 ; CHECK-NEXT: br i1 [[EXITCOND_NOT_I_I]], label [[EXIT:%.*]], label [[BB6_I_I]]
29 ; CHECK-NEXT: [[DOTSROA_0_0_COPYLOAD:%.*]] = load i16, ptr [[DATA]], align 2
30 ; CHECK-NEXT: ret i16 [[DOTSROA_0_0_COPYLOAD]]
33 %data = alloca [2 x i8], align 2
34 store i16 %0, ptr %data, align 2
35 %1 = getelementptr inbounds i8, ptr %data, i64 2
36 %2 = getelementptr inbounds i8, ptr %1, i64 -1
40 %iter.sroa.0.07.i.i = phi i64 [ %4, %bb6.i.i ], [ 0, %start ]
41 %3 = xor i64 %iter.sroa.0.07.i.i, -1
42 %_40.i.i = add nsw i64 1, %3
43 %4 = add nuw nsw i64 %iter.sroa.0.07.i.i, 1
44 %_34.i.i = getelementptr inbounds [0 x i8], ptr %data, i64 0, i64 %iter.sroa.0.07.i.i
45 %_39.i.i = getelementptr inbounds [0 x i8], ptr %2, i64 0, i64 %_40.i.i
46 %tmp.0.copyload.i.i.i.i = load i8, ptr %_34.i.i, align 1
47 %tmp2.0.copyload.i.i.i.i = load i8, ptr %_39.i.i, align 1
48 store i8 %tmp2.0.copyload.i.i.i.i, ptr %_34.i.i, align 1
49 store i8 %tmp.0.copyload.i.i.i.i, ptr %_39.i.i, align 1
50 %exitcond.not.i.i = icmp eq i64 %4, %x
51 br i1 %exitcond.not.i.i, label %exit, label %bb6.i.i
54 %.sroa.0.0.copyload = load i16, ptr %data, align 2
55 ret i16 %.sroa.0.0.copyload
58 define i16 @test(i16 %arg) {
60 ; CHECK-NEXT: bb6.i.i.i:
61 ; CHECK-NEXT: [[DATA_I_SROA_0_0_INSERT_INSERT:%.*]] = tail call i16 @llvm.bswap.i16(i16 [[ARG:%.*]])
62 ; CHECK-NEXT: ret i16 [[DATA_I_SROA_0_0_INSERT_INSERT]]
64 %ret = call i16 @helper(i16 %arg, i64 1)