1a4e88cbaSQuentin Colombet; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2 2a4e88cbaSQuentin Colombet; Check that the default heuristic use the local cse constraints. 3a4e88cbaSQuentin Colombet; RUN: opt -S -passes=reassociate,early-cse %s -o - | FileCheck %s -check-prefix=LOCAL_CSE 4a4e88cbaSQuentin Colombet; RUN: opt -S -passes=reassociate,early-cse %s -reassociate-use-cse-local=true -o - | FileCheck %s -check-prefix=LOCAL_CSE 5a4e88cbaSQuentin Colombet; RUN: opt -S -passes=reassociate,early-cse %s -reassociate-use-cse-local=false -o - | FileCheck %s -check-prefix=CSE 6a4e88cbaSQuentin Colombet 7a4e88cbaSQuentin Colombet 8a4e88cbaSQuentin Colombet; Check that when we use the heuristic to expose only local (to the first 9a4e88cbaSQuentin Colombet; encountered block) CSE opportunities, we choose the right sub expression 10a4e88cbaSQuentin Colombet; to expose. 11a4e88cbaSQuentin Colombet; 12a4e88cbaSQuentin Colombet; In these example we have three chains of expressions: 13a4e88cbaSQuentin Colombet; chain a: inv1, val_bb2, inv2, inv4 14a4e88cbaSQuentin Colombet; chain b: inv1, val_bb2, inv2, inv5 15a4e88cbaSQuentin Colombet; chain c: inv1, val_bb2, inv3 16a4e88cbaSQuentin Colombet; 17a4e88cbaSQuentin Colombet; The CSE-able pairs with there respective occurrences are: 18a4e88cbaSQuentin Colombet; inv1, val_bb2: 3 19a4e88cbaSQuentin Colombet; inv1, inv2: 2 20a4e88cbaSQuentin Colombet; 21a4e88cbaSQuentin Colombet; val_bb2 is anchored in bb2 but inv1 and inv2 can start in bb1. 22a4e88cbaSQuentin Colombet; With the local heuristic we will push inv1, inv2 at the beginning 23a4e88cbaSQuentin Colombet; of chain_a and chain_b. 24a4e88cbaSQuentin Colombet; With the non-local heuristic we will push inv1, val_bb2. 25a4e88cbaSQuentin Colombetdefine void @chain_spanning_several_blocks(i64 %inv1, i64 %inv2, i64 %inv3, i64 %inv4, i64 %inv5) { 26a4e88cbaSQuentin Colombet; LOCAL_CSE-LABEL: define void @chain_spanning_several_blocks 27a4e88cbaSQuentin Colombet; LOCAL_CSE-SAME: (i64 [[INV1:%.*]], i64 [[INV2:%.*]], i64 [[INV3:%.*]], i64 [[INV4:%.*]], i64 [[INV5:%.*]]) { 28a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: bb1: 29*73e22ff3SAkshay Deodhar; LOCAL_CSE-NEXT: [[CHAIN_A0:%.*]] = add nuw nsw i64 [[INV2]], [[INV1]] 30a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: br label [[BB2:%.*]] 31a4e88cbaSQuentin Colombet; LOCAL_CSE: bb2: 32a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: [[VAL_BB2:%.*]] = call i64 @get_val() 33*73e22ff3SAkshay Deodhar; LOCAL_CSE-NEXT: [[CHAIN_A1:%.*]] = add nuw nsw i64 [[CHAIN_A0]], [[INV4]] 34*73e22ff3SAkshay Deodhar; LOCAL_CSE-NEXT: [[CHAIN_A2:%.*]] = add nuw nsw i64 [[CHAIN_A1]], [[VAL_BB2]] 35*73e22ff3SAkshay Deodhar; LOCAL_CSE-NEXT: [[CHAIN_B1:%.*]] = add nuw nsw i64 [[CHAIN_A0]], [[INV5]] 36*73e22ff3SAkshay Deodhar; LOCAL_CSE-NEXT: [[CHAIN_B2:%.*]] = add nuw nsw i64 [[CHAIN_B1]], [[VAL_BB2]] 37*73e22ff3SAkshay Deodhar; LOCAL_CSE-NEXT: [[CHAIN_C0:%.*]] = add nuw nsw i64 [[INV3]], [[INV1]] 38*73e22ff3SAkshay Deodhar; LOCAL_CSE-NEXT: [[CHAIN_C1:%.*]] = add nuw nsw i64 [[CHAIN_C0]], [[VAL_BB2]] 39a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: call void @keep_alive(i64 [[CHAIN_A2]]) 40a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: call void @keep_alive(i64 [[CHAIN_B2]]) 41a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: call void @keep_alive(i64 [[CHAIN_C1]]) 42a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: ret void 43a4e88cbaSQuentin Colombet; 44a4e88cbaSQuentin Colombet; CSE-LABEL: define void @chain_spanning_several_blocks 45a4e88cbaSQuentin Colombet; CSE-SAME: (i64 [[INV1:%.*]], i64 [[INV2:%.*]], i64 [[INV3:%.*]], i64 [[INV4:%.*]], i64 [[INV5:%.*]]) { 46a4e88cbaSQuentin Colombet; CSE-NEXT: bb1: 47a4e88cbaSQuentin Colombet; CSE-NEXT: br label [[BB2:%.*]] 48a4e88cbaSQuentin Colombet; CSE: bb2: 49a4e88cbaSQuentin Colombet; CSE-NEXT: [[VAL_BB2:%.*]] = call i64 @get_val() 50*73e22ff3SAkshay Deodhar; CSE-NEXT: [[CHAIN_A0:%.*]] = add nuw nsw i64 [[VAL_BB2]], [[INV1]] 51*73e22ff3SAkshay Deodhar; CSE-NEXT: [[CHAIN_A1:%.*]] = add nuw nsw i64 [[CHAIN_A0]], [[INV2]] 52db32d11aSDavid Green; CSE-NEXT: [[CHAIN_A2:%.*]] = add nuw nsw i64 [[CHAIN_A1]], [[INV4]] 53a4e88cbaSQuentin Colombet; CSE-NEXT: [[CHAIN_B2:%.*]] = add nuw nsw i64 [[CHAIN_A1]], [[INV5]] 54*73e22ff3SAkshay Deodhar; CSE-NEXT: [[CHAIN_C1:%.*]] = add nuw nsw i64 [[CHAIN_A0]], [[INV3]] 55a4e88cbaSQuentin Colombet; CSE-NEXT: call void @keep_alive(i64 [[CHAIN_A2]]) 56a4e88cbaSQuentin Colombet; CSE-NEXT: call void @keep_alive(i64 [[CHAIN_B2]]) 57a4e88cbaSQuentin Colombet; CSE-NEXT: call void @keep_alive(i64 [[CHAIN_C1]]) 58a4e88cbaSQuentin Colombet; CSE-NEXT: ret void 59a4e88cbaSQuentin Colombet; 60a4e88cbaSQuentin Colombetbb1: 61a4e88cbaSQuentin Colombet %chain_a0 = add nuw nsw i64 %inv1, %inv2 62a4e88cbaSQuentin Colombet br label %bb2 63a4e88cbaSQuentin Colombet 64a4e88cbaSQuentin Colombetbb2: 65a4e88cbaSQuentin Colombet %val_bb2 = call i64 @get_val() 66a4e88cbaSQuentin Colombet %chain_a1 = add nuw nsw i64 %chain_a0, %val_bb2 67a4e88cbaSQuentin Colombet %chain_a2 = add nuw nsw i64 %chain_a1, %inv4 68a4e88cbaSQuentin Colombet %chain_b0 = add nuw nsw i64 %val_bb2, %inv1 69a4e88cbaSQuentin Colombet %chain_b1 = add nuw nsw i64 %chain_b0, %inv2 70a4e88cbaSQuentin Colombet %chain_b2 = add nuw nsw i64 %chain_b1, %inv5 71a4e88cbaSQuentin Colombet %chain_c0 = add nuw nsw i64 %val_bb2, %inv3 72a4e88cbaSQuentin Colombet %chain_c1 = add nuw nsw i64 %chain_c0, %inv1 73a4e88cbaSQuentin Colombet call void @keep_alive(i64 %chain_a2) 74a4e88cbaSQuentin Colombet call void @keep_alive(i64 %chain_b2) 75a4e88cbaSQuentin Colombet call void @keep_alive(i64 %chain_c1) 76a4e88cbaSQuentin Colombet ret void 77a4e88cbaSQuentin Colombet} 78a4e88cbaSQuentin Colombet 79a4e88cbaSQuentin Colombet; Same as @chain_spanning_several_blocks, but with values that are all anchored 80a4e88cbaSQuentin Colombet; on the non-entry block. 81a4e88cbaSQuentin Colombet; I.e., same pair map as previous but with invX_bbY instead of invX. 82a4e88cbaSQuentin Colombet; Note: Although %inv1_bb0 is anchored in the entry block, it doesn't constrain 83a4e88cbaSQuentin Colombet; the sub expressions on the entry block because we need to see at least two 84a4e88cbaSQuentin Colombet; values to be able to form a sub-expression and thus only the second one 85a4e88cbaSQuentin Colombet; add a constraint. 86a4e88cbaSQuentin Colombetdefine void @chain_spanning_several_blocks_no_entry_anchor() { 87a4e88cbaSQuentin Colombet; LOCAL_CSE-LABEL: define void @chain_spanning_several_blocks_no_entry_anchor() { 88a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: bb0: 89a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: [[INV2_BB0:%.*]] = call i64 @get_val() 90a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: br label [[BB1:%.*]] 91a4e88cbaSQuentin Colombet; LOCAL_CSE: bb1: 92a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: [[INV1_BB1:%.*]] = call i64 @get_val() 93*73e22ff3SAkshay Deodhar; LOCAL_CSE-NEXT: [[CHAIN_A0:%.*]] = add nuw nsw i64 [[INV1_BB1]], [[INV2_BB0]] 94a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: br label [[BB2:%.*]] 95a4e88cbaSQuentin Colombet; LOCAL_CSE: bb2: 96a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: [[INV3_BB2:%.*]] = call i64 @get_val() 97a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: [[INV4_BB2:%.*]] = call i64 @get_val() 98a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: [[INV5_BB2:%.*]] = call i64 @get_val() 99a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: [[VAL_BB2:%.*]] = call i64 @get_val() 100*73e22ff3SAkshay Deodhar; LOCAL_CSE-NEXT: [[CHAIN_A1:%.*]] = add nuw nsw i64 [[CHAIN_A0]], [[INV4_BB2]] 101*73e22ff3SAkshay Deodhar; LOCAL_CSE-NEXT: [[CHAIN_A2:%.*]] = add nuw nsw i64 [[CHAIN_A1]], [[VAL_BB2]] 102*73e22ff3SAkshay Deodhar; LOCAL_CSE-NEXT: [[CHAIN_B1:%.*]] = add nuw nsw i64 [[CHAIN_A0]], [[INV5_BB2]] 103*73e22ff3SAkshay Deodhar; LOCAL_CSE-NEXT: [[CHAIN_B2:%.*]] = add nuw nsw i64 [[CHAIN_B1]], [[VAL_BB2]] 104*73e22ff3SAkshay Deodhar; LOCAL_CSE-NEXT: [[CHAIN_C0:%.*]] = add nuw nsw i64 [[VAL_BB2]], [[INV1_BB1]] 105*73e22ff3SAkshay Deodhar; LOCAL_CSE-NEXT: [[CHAIN_C1:%.*]] = add nuw nsw i64 [[CHAIN_C0]], [[INV3_BB2]] 106a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: call void @keep_alive(i64 [[CHAIN_A2]]) 107a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: call void @keep_alive(i64 [[CHAIN_B2]]) 108a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: call void @keep_alive(i64 [[CHAIN_C1]]) 109a4e88cbaSQuentin Colombet; LOCAL_CSE-NEXT: ret void 110a4e88cbaSQuentin Colombet; 111a4e88cbaSQuentin Colombet; CSE-LABEL: define void @chain_spanning_several_blocks_no_entry_anchor() { 112a4e88cbaSQuentin Colombet; CSE-NEXT: bb0: 113a4e88cbaSQuentin Colombet; CSE-NEXT: [[INV2_BB0:%.*]] = call i64 @get_val() 114a4e88cbaSQuentin Colombet; CSE-NEXT: br label [[BB1:%.*]] 115a4e88cbaSQuentin Colombet; CSE: bb1: 116a4e88cbaSQuentin Colombet; CSE-NEXT: [[INV1_BB1:%.*]] = call i64 @get_val() 117a4e88cbaSQuentin Colombet; CSE-NEXT: br label [[BB2:%.*]] 118a4e88cbaSQuentin Colombet; CSE: bb2: 119a4e88cbaSQuentin Colombet; CSE-NEXT: [[INV3_BB2:%.*]] = call i64 @get_val() 120a4e88cbaSQuentin Colombet; CSE-NEXT: [[INV4_BB2:%.*]] = call i64 @get_val() 121a4e88cbaSQuentin Colombet; CSE-NEXT: [[INV5_BB2:%.*]] = call i64 @get_val() 122a4e88cbaSQuentin Colombet; CSE-NEXT: [[VAL_BB2:%.*]] = call i64 @get_val() 123*73e22ff3SAkshay Deodhar; CSE-NEXT: [[CHAIN_A0:%.*]] = add nuw nsw i64 [[VAL_BB2]], [[INV1_BB1]] 124*73e22ff3SAkshay Deodhar; CSE-NEXT: [[CHAIN_A1:%.*]] = add nuw nsw i64 [[CHAIN_A0]], [[INV2_BB0]] 125db32d11aSDavid Green; CSE-NEXT: [[CHAIN_A2:%.*]] = add nuw nsw i64 [[CHAIN_A1]], [[INV4_BB2]] 126a4e88cbaSQuentin Colombet; CSE-NEXT: [[CHAIN_B2:%.*]] = add nuw nsw i64 [[CHAIN_A1]], [[INV5_BB2]] 127*73e22ff3SAkshay Deodhar; CSE-NEXT: [[CHAIN_C1:%.*]] = add nuw nsw i64 [[CHAIN_A0]], [[INV3_BB2]] 128a4e88cbaSQuentin Colombet; CSE-NEXT: call void @keep_alive(i64 [[CHAIN_A2]]) 129a4e88cbaSQuentin Colombet; CSE-NEXT: call void @keep_alive(i64 [[CHAIN_B2]]) 130a4e88cbaSQuentin Colombet; CSE-NEXT: call void @keep_alive(i64 [[CHAIN_C1]]) 131a4e88cbaSQuentin Colombet; CSE-NEXT: ret void 132a4e88cbaSQuentin Colombet; 133a4e88cbaSQuentin Colombetbb0: 134a4e88cbaSQuentin Colombet %inv2_bb0 = call i64 @get_val() 135a4e88cbaSQuentin Colombet br label %bb1 136a4e88cbaSQuentin Colombet 137a4e88cbaSQuentin Colombetbb1: 138a4e88cbaSQuentin Colombet %inv1_bb1 = call i64 @get_val() 139a4e88cbaSQuentin Colombet %chain_a0 = add nuw nsw i64 %inv1_bb1, %inv2_bb0 140a4e88cbaSQuentin Colombet br label %bb2 141a4e88cbaSQuentin Colombet 142a4e88cbaSQuentin Colombetbb2: 143a4e88cbaSQuentin Colombet %inv3_bb2 = call i64 @get_val() 144a4e88cbaSQuentin Colombet %inv4_bb2 = call i64 @get_val() 145a4e88cbaSQuentin Colombet %inv5_bb2 = call i64 @get_val() 146a4e88cbaSQuentin Colombet %val_bb2 = call i64 @get_val() 147a4e88cbaSQuentin Colombet %chain_a1 = add nuw nsw i64 %chain_a0, %val_bb2 148a4e88cbaSQuentin Colombet %chain_a2 = add nuw nsw i64 %chain_a1, %inv4_bb2 149a4e88cbaSQuentin Colombet %chain_b0 = add nuw nsw i64 %val_bb2, %inv1_bb1 150a4e88cbaSQuentin Colombet %chain_b1 = add nuw nsw i64 %chain_b0, %inv2_bb0 151a4e88cbaSQuentin Colombet %chain_b2 = add nuw nsw i64 %chain_b1, %inv5_bb2 152a4e88cbaSQuentin Colombet %chain_c0 = add nuw nsw i64 %val_bb2, %inv3_bb2 153a4e88cbaSQuentin Colombet %chain_c1 = add nuw nsw i64 %chain_c0, %inv1_bb1 154a4e88cbaSQuentin Colombet call void @keep_alive(i64 %chain_a2) 155a4e88cbaSQuentin Colombet call void @keep_alive(i64 %chain_b2) 156a4e88cbaSQuentin Colombet call void @keep_alive(i64 %chain_c1) 157a4e88cbaSQuentin Colombet ret void 158a4e88cbaSQuentin Colombet} 159a4e88cbaSQuentin Colombetdeclare i64 @get_val() 160a4e88cbaSQuentin Colombetdeclare void @keep_alive(i64) 161