brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · 3094d98 Raw
145 lines · plain
1; RUN: opt < %s -passes=sink -S | FileCheck %s2; RUN: opt < %s -aa-pipeline='basic-aa' -passes='sink' -S | FileCheck %s3 4@A = external global i325@B = external global i326 7; Sink should sink the load past the store (which doesn't overlap) into8; the block that uses it.9 10;      CHECK-LABEL: @foo(11;      CHECK: true:12; CHECK-NEXT: %l = load i32, ptr @A13; CHECK-NEXT: ret i32 %l14 15define i32 @foo(i1 %z) {16  %l = load i32, ptr @A17  store i32 0, ptr @B18  br i1 %z, label %true, label %false19true:20  ret i32 %l21false:22  ret i32 023}24 25; But don't sink load volatiles...26 27;      CHECK-LABEL: @foo2(28;      CHECK: load volatile29; CHECK-NEXT: store i3230 31define i32 @foo2(i1 %z) {32  %l = load volatile i32, ptr @A33  store i32 0, ptr @B34  br i1 %z, label %true, label %false35true:36  ret i32 %l37false:38  ret i32 039}40 41; Sink to the nearest post-dominator42 43;      CHECK-LABEL: @diamond(44;      CHECK: X:45; CHECK-NEXT: phi46; CHECK-NEXT: mul nsw47; CHECK-NEXT: sub48 49define i32 @diamond(i32 %a, i32 %b, i32 %c) {50  %1 = mul nsw i32 %c, %b51  %2 = icmp sgt i32 %a, 052  br i1 %2, label %B0, label %B153 54B0:                                       ; preds = %055  br label %X56 57B1:                                      ; preds = %058  br label %X59 60X:                                     ; preds = %5, %361  %.01 = phi i32 [ %c, %B0 ], [ %a, %B1 ]62  %R = sub i32 %1, %.0163  ret i32 %R64}65 66; We shouldn't sink constant sized allocas from the entry block, since CodeGen67; interprets allocas outside the entry block as dynamically sized stack objects.68 69; CHECK-LABEL: @alloca_nosink70; CHECK: entry:71; CHECK-NEXT: alloca72define i32 @alloca_nosink(i32 %a, i32 %b) {73entry:74  %0 = alloca i3275  %1 = icmp ne i32 %a, 076  br i1 %1, label %if, label %endif77 78if:79  %2 = getelementptr i32, ptr %0, i32 180  store i32 0, ptr %081  store i32 1, ptr %282  %3 = getelementptr i32, ptr %0, i32 %b83  %4 = load i32, ptr %384  ret i32 %485 86endif:87  ret i32 088}89 90; Make sure we sink dynamic sized allocas91 92; CHECK-LABEL: @alloca_sink_dynamic93; CHECK: entry:94; CHECK-NOT: alloca95; CHECK: if:96; CHECK-NEXT: alloca97define i32 @alloca_sink_dynamic(i32 %a, i32 %b, i32 %size) {98entry:99  %0 = alloca i32, i32 %size100  %1 = icmp ne i32 %a, 0101  br i1 %1, label %if, label %endif102 103if:104  %2 = getelementptr i32, ptr %0, i32 1105  store i32 0, ptr %0106  store i32 1, ptr %2107  %3 = getelementptr i32, ptr %0, i32 %b108  %4 = load i32, ptr %3109  ret i32 %4110 111endif:112  ret i32 0113}114 115; We also want to sink allocas that are not in the entry block.  These116; will already be considered as dynamically sized stack objects, so sinking117; them does no further damage.118 119; CHECK-LABEL: @alloca_sink_nonentry120; CHECK: if0:121; CHECK-NOT: alloca122; CHECK: if:123; CHECK-NEXT: alloca124define i32 @alloca_sink_nonentry(i32 %a, i32 %b, i32 %c) {125entry:126  %cmp = icmp ne i32 %c, 0127  br i1 %cmp, label %endif, label %if0128 129if0:130  %0 = alloca i32131  %1 = icmp ne i32 %a, 0132  br i1 %1, label %if, label %endif133 134if:135  %2 = getelementptr i32, ptr %0, i32 1136  store i32 0, ptr %0137  store i32 1, ptr %2138  %3 = getelementptr i32, ptr %0, i32 %b139  %4 = load i32, ptr %3140  ret i32 %4141 142endif:143  ret i32 0144}145