xref: /llvm-project/llvm/test/Transforms/LoopStrengthReduce/canonical-form.ll (revision 6444a65514b58c6df7db41151e982e7859ac2548)
1; RUN: opt -S -loop-reduce < %s | FileCheck %s
2
3; Check that no crash here.
4; When GenerateICmpZeroScales transforms the base formula
5; it can get non-canonical form.
6
7target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
8target triple = "x86_64-unknown-linux-gnu"
9
10define void @hoge(i32 %arg) {
11; CHECK: @hoge
12bb:
13  %tmp = and i32 %arg, -8
14  br label %bb2
15
16bb1:                                              ; preds = %bb2
17  ret void
18
19bb2:                                              ; preds = %bb2, %bb
20  %tmp3 = phi i64 [ 0, %bb ], [ %tmp62, %bb2 ]
21  %tmp4 = phi i32 [ 1, %bb ], [ %tmp63, %bb2 ]
22  %tmp5 = phi i32 [ 0, %bb ], [ %tmp64, %bb2 ]
23  %tmp6 = add i64 %tmp3, 1
24  %tmp7 = trunc i64 %tmp6 to i32
25  %tmp8 = sub i32 %tmp4, %tmp7
26  %tmp9 = mul i32 %tmp8, %tmp8
27  %tmp10 = sub i32 %tmp9, %tmp8
28  %tmp11 = sext i32 %tmp10 to i64
29  %tmp12 = sub i64 %tmp6, %tmp11
30  %tmp13 = add nuw nsw i32 %tmp4, 1
31  %tmp14 = add i64 %tmp12, 1
32  %tmp15 = trunc i64 %tmp14 to i32
33  %tmp16 = sub i32 %tmp13, %tmp15
34  %tmp17 = mul i32 %tmp16, %tmp16
35  %tmp18 = sub i32 %tmp17, %tmp16
36  %tmp19 = sext i32 %tmp18 to i64
37  %tmp20 = sub i64 %tmp14, %tmp19
38  %tmp21 = add i64 %tmp20, 1
39  %tmp22 = sub i64 %tmp21, 0
40  %tmp23 = add nuw nsw i32 %tmp4, 3
41  %tmp24 = add i64 %tmp22, 1
42  %tmp25 = trunc i64 %tmp24 to i32
43  %tmp26 = sub i32 %tmp23, %tmp25
44  %tmp27 = mul i32 %tmp26, %tmp26
45  %tmp28 = sub i32 %tmp27, %tmp26
46  %tmp29 = sext i32 %tmp28 to i64
47  %tmp30 = sub i64 %tmp24, %tmp29
48  %tmp31 = add nuw nsw i32 %tmp4, 4
49  %tmp32 = add i64 %tmp30, 1
50  %tmp33 = trunc i64 %tmp32 to i32
51  %tmp34 = sub i32 %tmp31, %tmp33
52  %tmp35 = mul i32 %tmp34, %tmp34
53  %tmp36 = sub i32 %tmp35, %tmp34
54  %tmp37 = sext i32 %tmp36 to i64
55  %tmp38 = sub i64 %tmp32, %tmp37
56  %tmp39 = add nuw nsw i32 %tmp4, 5
57  %tmp40 = add i64 %tmp38, 1
58  %tmp41 = trunc i64 %tmp40 to i32
59  %tmp42 = sub i32 %tmp39, %tmp41
60  %tmp43 = mul i32 %tmp42, %tmp42
61  %tmp44 = sub i32 %tmp43, %tmp42
62  %tmp45 = sext i32 %tmp44 to i64
63  %tmp46 = sub i64 %tmp40, %tmp45
64  %tmp47 = add nuw nsw i32 %tmp4, 6
65  %tmp48 = add i64 %tmp46, 1
66  %tmp49 = trunc i64 %tmp48 to i32
67  %tmp50 = sub i32 %tmp47, %tmp49
68  %tmp51 = mul i32 %tmp50, %tmp50
69  %tmp52 = sub i32 %tmp51, %tmp50
70  %tmp53 = sext i32 %tmp52 to i64
71  %tmp54 = sub i64 %tmp48, %tmp53
72  %tmp55 = add nuw nsw i32 %tmp4, 7
73  %tmp56 = add i64 %tmp54, 1
74  %tmp57 = trunc i64 %tmp56 to i32
75  %tmp58 = sub i32 %tmp55, %tmp57
76  %tmp59 = mul i32 %tmp58, %tmp58
77  %tmp60 = sub i32 %tmp59, %tmp58
78  %tmp61 = sext i32 %tmp60 to i64
79  %tmp62 = sub i64 %tmp56, %tmp61
80  %tmp63 = add nuw nsw i32 %tmp4, 8
81  %tmp64 = add i32 %tmp5, 8
82  %tmp65 = icmp eq i32 %tmp64, %tmp
83  br i1 %tmp65, label %bb1, label %bb2
84}
85