xref: /llvm-project/llvm/test/Transforms/LoopFlatten/widen-iv2.ll (revision dce77a357948709e335910ddc07f9c3f2eb2ac4b)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2
3; This checks updating of phi nodes when the transformation is deemed
4; unprofitable after IV widening.
5
6; RUN: opt < %s -S -passes='loop(loop-flatten),verify' \
7; RUN:     -verify-loop-info -verify-dom-info -verify-scev | \
8; RUN:     FileCheck %s --check-prefix=CHECK
9
10target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
11
12@d = dso_local global i32 0, align 4
13@b = internal global i32 0, align 4
14@a = internal global i32 0, align 4
15@c = dso_local global ptr null, align 8
16
17define dso_local i32 @fn1() local_unnamed_addr #0 {
18; CHECK-LABEL: @fn1(
19; CHECK-NEXT:  entry:
20; CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr @d, align 4
21; CHECK-NEXT:    store i32 [[TMP0]], ptr @b, align 4
22; CHECK-NEXT:    store i32 [[TMP0]], ptr @a, align 4
23; CHECK-NEXT:    [[CMP15:%.*]] = icmp sgt i32 [[TMP0]], 0
24; CHECK-NEXT:    br i1 [[CMP15]], label [[FOR_COND1_PREHEADER_US_PREHEADER:%.*]], label [[FOR_END6:%.*]]
25; CHECK:       for.cond1.preheader.us.preheader:
26; CHECK-NEXT:    [[TMP1:%.*]] = sext i32 [[TMP0]] to i64
27; CHECK-NEXT:    [[TMP2:%.*]] = sext i32 [[TMP0]] to i64
28; CHECK-NEXT:    [[TMP3:%.*]] = sext i32 [[TMP0]] to i64
29; CHECK-NEXT:    br label [[FOR_COND1_PREHEADER_US:%.*]]
30; CHECK:       for.cond1.preheader.us:
31; CHECK-NEXT:    [[INDVAR2:%.*]] = phi i64 [ [[INDVAR_NEXT3:%.*]], [[FOR_COND1_FOR_INC4_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND1_PREHEADER_US_PREHEADER]] ]
32; CHECK-NEXT:    [[I_016_US:%.*]] = phi i32 [ [[INC5_US:%.*]], [[FOR_COND1_FOR_INC4_CRIT_EDGE_US]] ], [ 0, [[FOR_COND1_PREHEADER_US_PREHEADER]] ]
33; CHECK-NEXT:    [[TMP4:%.*]] = load ptr, ptr @c, align 8
34; CHECK-NEXT:    [[TMP5:%.*]] = mul nsw i64 [[INDVAR2]], [[TMP2]]
35; CHECK-NEXT:    [[MUL_US:%.*]] = mul nsw i32 [[I_016_US]], [[TMP0]]
36; CHECK-NEXT:    [[TMP6:%.*]] = sext i32 [[MUL_US]] to i64
37; CHECK-NEXT:    br label [[FOR_BODY3_US:%.*]]
38; CHECK:       for.body3.us:
39; CHECK-NEXT:    [[INDVAR:%.*]] = phi i64 [ [[INDVAR_NEXT:%.*]], [[FOR_BODY3_US]] ], [ 0, [[FOR_COND1_PREHEADER_US]] ]
40; CHECK-NEXT:    [[J_014_US:%.*]] = phi i32 [ 0, [[FOR_COND1_PREHEADER_US]] ], [ [[INC_US:%.*]], [[FOR_BODY3_US]] ]
41; CHECK-NEXT:    [[TMP7:%.*]] = add nsw i64 [[INDVAR]], [[TMP5]]
42; CHECK-NEXT:    [[TMP8:%.*]] = sext i32 [[J_014_US]] to i64
43; CHECK-NEXT:    [[TMP9:%.*]] = add nsw i64 [[TMP8]], [[TMP5]]
44; CHECK-NEXT:    [[ADD_US:%.*]] = add nsw i32 [[J_014_US]], [[MUL_US]]
45; CHECK-NEXT:    [[IDXPROM_US:%.*]] = sext i32 [[ADD_US]] to i64
46; CHECK-NEXT:    [[ARRAYIDX_US:%.*]] = getelementptr inbounds i32, ptr [[TMP4]], i64 [[TMP7]]
47; CHECK-NEXT:    store i32 32, ptr [[ARRAYIDX_US]], align 4
48; CHECK-NEXT:    [[INDVAR_NEXT]] = add nuw nsw i64 [[INDVAR]], 1
49; CHECK-NEXT:    [[INC_US]] = add nuw nsw i32 [[J_014_US]], 1
50; CHECK-NEXT:    [[CMP2_US:%.*]] = icmp slt i64 [[INDVAR_NEXT]], [[TMP1]]
51; CHECK-NEXT:    br i1 [[CMP2_US]], label [[FOR_BODY3_US]], label [[FOR_COND1_FOR_INC4_CRIT_EDGE_US]]
52; CHECK:       for.cond1.for.inc4_crit_edge.us:
53; CHECK-NEXT:    [[INDVAR_NEXT3]] = add nuw nsw i64 [[INDVAR2]], 1
54; CHECK-NEXT:    [[INC5_US]] = add nuw nsw i32 [[I_016_US]], 1
55; CHECK-NEXT:    [[CMP_US:%.*]] = icmp slt i64 [[INDVAR_NEXT3]], [[TMP3]]
56; CHECK-NEXT:    br i1 [[CMP_US]], label [[FOR_COND1_PREHEADER_US]], label [[FOR_END6_LOOPEXIT:%.*]]
57; CHECK:       for.end6.loopexit:
58; CHECK-NEXT:    br label [[FOR_END6]]
59; CHECK:       for.end6:
60; CHECK-NEXT:    ret i32 undef
61;
62entry:
63  %0 = load i32, ptr @d, align 4
64  store i32 %0, ptr @b, align 4
65  store i32 %0, ptr @a, align 4
66  %cmp15 = icmp sgt i32 %0, 0
67  br i1 %cmp15, label %for.cond1.preheader.us.preheader, label %for.end6
68
69for.cond1.preheader.us.preheader:
70  br label %for.cond1.preheader.us
71
72for.cond1.preheader.us:
73  %i.016.us = phi i32 [ %inc5.us, %for.cond1.for.inc4_crit_edge.us ], [ 0, %for.cond1.preheader.us.preheader ]
74  %1 = load ptr, ptr @c, align 8
75  %mul.us = mul nsw i32 %i.016.us, %0
76  br label %for.body3.us
77
78for.body3.us:
79  %j.014.us = phi i32 [ 0, %for.cond1.preheader.us ], [ %inc.us, %for.body3.us ]
80  %add.us = add nsw i32 %j.014.us, %mul.us
81  %idxprom.us = sext i32 %add.us to i64
82  %arrayidx.us = getelementptr inbounds i32, ptr %1, i64 %idxprom.us
83  store i32 32, ptr %arrayidx.us, align 4
84  %inc.us = add nuw nsw i32 %j.014.us, 1
85  %cmp2.us = icmp slt i32 %inc.us, %0
86  br i1 %cmp2.us, label %for.body3.us, label %for.cond1.for.inc4_crit_edge.us
87
88for.cond1.for.inc4_crit_edge.us:
89  %inc5.us = add nuw nsw i32 %i.016.us, 1
90  %cmp.us = icmp slt i32 %inc5.us, %0
91  br i1 %cmp.us, label %for.cond1.preheader.us, label %for.end6.loopexit
92
93for.end6.loopexit:
94  br label %for.end6
95
96for.end6:
97  ret i32 undef
98}
99