1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; Check that the default heuristic use the local cse constraints.
3 ; RUN: opt -S -passes=reassociate %s -o - | FileCheck %s -check-prefix=LOCAL_CSE
4 ; RUN: opt -S -passes=reassociate %s -reassociate-use-cse-local=true -o - | FileCheck %s -check-prefix=LOCAL_CSE
5 ; RUN: opt -S -passes=reassociate %s -reassociate-use-cse-local=false -o - | FileCheck %s -check-prefix=CSE
7 ; In the local CSE mode, we check that we don't create loop dependent
8 ; expressions in order to expose more CSE opportunities.
9 ; This can be seen with %inv4 and %inv5 that should stay in the entry block.
11 ; For the non-local CSE mode, we form CSE-able expression regardless of where
12 ; they would be materialized. In this case, %inv4 and %inv5 are pushed
13 ; down the loop body in order to make loop_dependent, %inv2 appear as a
16 ; Related to issue PR61458.
17 define void @reassoc_defeats_licm(i64 %inv1, i64 %inv2, i64 %inv3) {
18 ; LOCAL_CSE-LABEL: define void @reassoc_defeats_licm
19 ; LOCAL_CSE-SAME: (i64 [[INV1:%.*]], i64 [[INV2:%.*]], i64 [[INV3:%.*]]) {
21 ; LOCAL_CSE-NEXT: [[INV4:%.*]] = add nuw nsw i64 [[INV2]], [[INV1]]
22 ; LOCAL_CSE-NEXT: [[INV5:%.*]] = add nuw nsw i64 [[INV3]], [[INV2]]
23 ; LOCAL_CSE-NEXT: br label [[BB214:%.*]]
25 ; LOCAL_CSE-NEXT: [[IV1:%.*]] = phi i64 [ [[IV2:%.*]], [[BB214]] ], [ 0, [[BB:%.*]] ]
26 ; LOCAL_CSE-NEXT: [[IV2]] = phi i64 [ [[IV2_PLUS_1:%.*]], [[BB214]] ], [ 1, [[BB]] ]
27 ; LOCAL_CSE-NEXT: [[LOOP_DEPENDENT:%.*]] = shl nuw nsw i64 [[IV1]], 13
28 ; LOCAL_CSE-NEXT: [[LOOP_DEPENDENT2:%.*]] = add nsw i64 [[INV4]], [[LOOP_DEPENDENT]]
29 ; LOCAL_CSE-NEXT: call void @keep_alive(i64 [[LOOP_DEPENDENT2]])
30 ; LOCAL_CSE-NEXT: [[LOOP_DEPENDENT3:%.*]] = add i64 [[INV5]], [[LOOP_DEPENDENT]]
31 ; LOCAL_CSE-NEXT: call void @keep_alive(i64 [[LOOP_DEPENDENT3]])
32 ; LOCAL_CSE-NEXT: [[IV2_PLUS_1]] = add i64 [[IV2]], 1
33 ; LOCAL_CSE-NEXT: br label [[BB214]]
35 ; CSE-LABEL: define void @reassoc_defeats_licm
36 ; CSE-SAME: (i64 [[INV1:%.*]], i64 [[INV2:%.*]], i64 [[INV3:%.*]]) {
38 ; CSE-NEXT: br label [[BB214:%.*]]
40 ; CSE-NEXT: [[IV1:%.*]] = phi i64 [ [[IV2:%.*]], [[BB214]] ], [ 0, [[BB:%.*]] ]
41 ; CSE-NEXT: [[IV2]] = phi i64 [ [[IV2_PLUS_1:%.*]], [[BB214]] ], [ 1, [[BB]] ]
42 ; CSE-NEXT: [[LOOP_DEPENDENT:%.*]] = shl nuw nsw i64 [[IV1]], 13
43 ; CSE-NEXT: [[INV4:%.*]] = add i64 [[LOOP_DEPENDENT]], [[INV2]]
44 ; CSE-NEXT: [[LOOP_DEPENDENT2:%.*]] = add i64 [[INV4]], [[INV1]]
45 ; CSE-NEXT: call void @keep_alive(i64 [[LOOP_DEPENDENT2]])
46 ; CSE-NEXT: [[INV5:%.*]] = add i64 [[LOOP_DEPENDENT]], [[INV2]]
47 ; CSE-NEXT: [[LOOP_DEPENDENT3:%.*]] = add i64 [[INV5]], [[INV3]]
48 ; CSE-NEXT: call void @keep_alive(i64 [[LOOP_DEPENDENT3]])
49 ; CSE-NEXT: [[IV2_PLUS_1]] = add i64 [[IV2]], 1
50 ; CSE-NEXT: br label [[BB214]]
53 %inv4 = add nuw nsw i64 %inv1, %inv2
54 %inv5 = add nuw nsw i64 %inv2, %inv3
57 bb214: ; preds = %bb214, %bb
58 %iv1 = phi i64 [ %iv2, %bb214 ], [ 0, %bb ]
59 %iv2 = phi i64 [ %iv2_plus_1, %bb214 ], [ 1, %bb ]
60 %loop_dependent = shl nuw nsw i64 %iv1, 13
61 %loop_dependent2 = add nsw i64 %inv4, %loop_dependent
62 call void @keep_alive(i64 %loop_dependent2)
63 %loop_dependent3 = add i64 %inv5, %loop_dependent
64 call void @keep_alive(i64 %loop_dependent3)
65 %iv2_plus_1 = add i64 %iv2, 1
69 declare void @keep_alive(i64)