Skip to content

Commit ba6bca6

Browse files
committed
[RLE-DSE] Move more tests to redundantloadelimination_basic.sil
1 parent 774dd10 commit ba6bca6

File tree

2 files changed

+171
-196
lines changed

2 files changed

+171
-196
lines changed

test/SILPasses/globalredundantloadelimination.sil

Lines changed: 0 additions & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -267,119 +267,6 @@ bb0(%0 : $*Optional<B>):
267267
return %9999 : $()
268268
}
269269

270-
271-
// CHECK-LABEL: sil @load_to_load_conflicting_branches_diamond : $@convention(thin) (@inout Builtin.Int32) -> () {
272-
// CHECK: bb0(
273-
// CHECK: load
274-
// CHECK: bb1:
275-
// CHECK-NOT: load
276-
// CHECK: store
277-
// CHECK-NOT: load
278-
// CHECK: bb2:
279-
// CHECK: bb3:
280-
// CHECK: load
281-
sil @load_to_load_conflicting_branches_diamond : $@convention(thin) (@inout Builtin.Int32) -> () {
282-
bb0(%0 : $*Builtin.Int32):
283-
%1 = load %0 : $*Builtin.Int32
284-
builtin "trunc_Int32_Int1"(%1 : $Builtin.Int32) : $Builtin.Int1
285-
cond_br undef, bb1, bb2
286-
287-
bb1:
288-
%3 = load %0 : $*Builtin.Int32
289-
%4 = integer_literal $Builtin.Int32, 2
290-
builtin "trunc_Int32_Int1"(%3 : $Builtin.Int32) : $Builtin.Int1
291-
store %4 to %0 : $*Builtin.Int32
292-
builtin "trunc_Int32_Int1"(%3 : $Builtin.Int32) : $Builtin.Int1
293-
%5 = load %0 : $*Builtin.Int32
294-
builtin "trunc_Int32_Int1"(%5 : $Builtin.Int32) : $Builtin.Int1
295-
br bb3
296-
297-
bb2:
298-
%6 = load %0 : $*Builtin.Int32
299-
builtin "trunc_Int32_Int1"(%6 : $Builtin.Int32) : $Builtin.Int1
300-
br bb3
301-
302-
bb3:
303-
%7 = load %0 : $*Builtin.Int32
304-
builtin "trunc_Int32_Int1"(%7 : $Builtin.Int32) : $Builtin.Int1
305-
%9999 = tuple()
306-
return %9999 : $()
307-
}
308-
309-
// CHECK-LABEL: sil @load_to_load_irreducible_loop : $@convention(thin) (@inout Builtin.Int32) -> () {
310-
// CHECK: bb0(
311-
// CHECK: load
312-
// CHECK: bb1:
313-
// CHECK: load
314-
// CHECK: store
315-
// CHECK-NOT: load
316-
// CHECK: bb2:
317-
// CHECK: bb3:
318-
// CHECK: load
319-
sil @load_to_load_irreducible_loop : $@convention(thin) (@inout Builtin.Int32) -> () {
320-
bb0(%0 : $*Builtin.Int32):
321-
%1 = load %0 : $*Builtin.Int32
322-
builtin "trunc_Int32_Int1"(%1 : $Builtin.Int32) : $Builtin.Int1
323-
cond_br undef, bb1, bb2
324-
325-
bb1:
326-
%3 = load %0 : $*Builtin.Int32
327-
%4 = integer_literal $Builtin.Int32, 2
328-
builtin "trunc_Int32_Int1"(%3 : $Builtin.Int32) : $Builtin.Int1
329-
store %4 to %0 : $*Builtin.Int32
330-
builtin "trunc_Int32_Int1"(%3 : $Builtin.Int32) : $Builtin.Int1
331-
%5 = load %0 : $*Builtin.Int32
332-
builtin "trunc_Int32_Int1"(%5 : $Builtin.Int32) : $Builtin.Int1
333-
cond_br undef, bb2, bb3
334-
335-
bb2:
336-
%6 = load %0 : $*Builtin.Int32
337-
builtin "trunc_Int32_Int1"(%6 : $Builtin.Int32) : $Builtin.Int1
338-
cond_br undef, bb1, bb3
339-
340-
bb3:
341-
%7 = load %0 : $*Builtin.Int32
342-
builtin "trunc_Int32_Int1"(%7 : $Builtin.Int32) : $Builtin.Int1
343-
%9999 = tuple()
344-
return %9999 : $()
345-
}
346-
347-
// CHECK-LABEL: sil @load_to_load_loop : $@convention(thin) (@inout Builtin.Int32, @inout Builtin.Int32) -> () {
348-
// CHECK: bb0([[PTR0:%[0-9]+]] : $*Builtin.Int32, [[PTR1:%[0-9]+]] : $*Builtin.Int32):
349-
// CHECK: load [[PTR0]]
350-
// CHECK: bb1:
351-
// CHECK: load [[PTR0]]
352-
// CHECK: store {{%[0-9]+}} to [[PTR0]]
353-
// CHECK-NOT: load
354-
// CHECK: bb2:
355-
// CHECK: load [[PTR1]]
356-
sil @load_to_load_loop : $@convention(thin) (@inout Builtin.Int32, @inout Builtin.Int32) -> () {
357-
bb0(%0 : $*Builtin.Int32, %1 : $*Builtin.Int32):
358-
%2 = load %0 : $*Builtin.Int32
359-
%99 = load %1 : $*Builtin.Int32
360-
builtin "trunc_Int32_Int1"(%2 : $Builtin.Int32) : $Builtin.Int1
361-
br bb1
362-
363-
bb1:
364-
%4 = load %0 : $*Builtin.Int32
365-
%5 = integer_literal $Builtin.Int32, 2
366-
builtin "trunc_Int32_Int1"(%4 : $Builtin.Int32) : $Builtin.Int1
367-
store %5 to %0 : $*Builtin.Int32
368-
builtin "trunc_Int32_Int1"(%4 : $Builtin.Int32) : $Builtin.Int1
369-
%6 = load %0 : $*Builtin.Int32
370-
builtin "trunc_Int32_Int1"(%6 : $Builtin.Int32) : $Builtin.Int1
371-
cond_br undef, bb1, bb2
372-
373-
bb2:
374-
%7 = load %0 : $*Builtin.Int32
375-
builtin "trunc_Int32_Int1"(%7 : $Builtin.Int32) : $Builtin.Int1
376-
%8 = load %1 : $*Builtin.Int32
377-
builtin "trunc_Int32_Int1"(%8 : $Builtin.Int32) : $Builtin.Int1
378-
%9999 = tuple()
379-
return %9999 : $()
380-
}
381-
382-
383270
// Don't bitcast differently sized structs.
384271
// CHECK-LABEL: sil @store_to_load_forward_unchecked_addr_cast_different_sized_struct
385272
// CHECK-NOT: unchecked_trivial_bit_cast
@@ -665,88 +552,6 @@ bb2:
665552
return %5 : $A
666553
}
667554

668-
// Forward store %1 and store %2 such that load %3 becomes an identity trivial cast.
669-
// Both loads from %0 will be eliminated.
670-
// CHECK-LABEL: sil @test_read_dependence_allows_forwarding_multi_bb_2 : $@convention(thin) (@inout A, A, A) -> A {
671-
// CHECK: bb0([[ARG_0:%.*]] : $*A, [[ARG_1:%.*]] : $A, {{%.*}} : $A):
672-
// CHECK: store
673-
// CHECK: br bb1([[ARG_1]] : $A)
674-
// CHECK: bb1([[PHI:%.*]] : $A):
675-
// CHECK-NEXT: unchecked_trivial_bit_cast
676-
// CHECK-NEXT: store
677-
// CHECK-NEXT: cond_br
678-
// CHECK: bb2:
679-
// CHECK: return [[PHI]] : $A
680-
sil @test_read_dependence_allows_forwarding_multi_bb_2 : $@convention(thin) (@inout A, A, A) -> A {
681-
bb0(%0 : $*A, %1 : $A, %2 : $A):
682-
store %1 to %0 : $*A
683-
%3 = unchecked_addr_cast %0 : $*A to $*A
684-
%4 = unchecked_addr_cast %3 : $*A to $*A
685-
br bb1
686-
687-
bb1:
688-
// This means that the first store is not dead.
689-
%6 = load %3 : $*A
690-
// But we still should be able to forward this load.
691-
%7 = load %0 : $*A
692-
// This load must be forwarded is needed to trigger the self loop forwarding. Once we do the full
693-
// optimistic dataflow this will no longer be needed.
694-
%8 = load %0 : $*A
695-
store %2 to %0 : $*A
696-
cond_br undef, bb1, bb2
697-
698-
bb2:
699-
return %7 : $A
700-
}
701-
702-
// Check load forwarding across strong_release in case the stored memory does
703-
// not escape.
704-
// CHECK-LABEL: sil @test_store_forwarding_strong_release
705-
// CHECK: strong_release
706-
// CHECK-NOT: [[BOX0:%.*]] = load
707-
// CHECK: apply
708-
sil @test_store_forwarding_strong_release : $@convention(thin) (B, X) -> () {
709-
bb0(%0 : $B, %1 : $X):
710-
%2 = alloc_stack $A // users: %3, %13
711-
%3 = struct_element_addr %2#1 : $*A, #A.i // users: %5, %10
712-
%4 = integer_literal $Builtin.Int32, 32 // user: %5
713-
store %4 to %3 : $*Builtin.Int32 // id: %5
714-
%6 = ref_to_unowned %0 : $B to $@sil_unowned B // user: %7
715-
unowned_release %6 : $@sil_unowned B // id: %7
716-
strong_release %0 : $B // id: %8
717-
release_value %1 : $X // id: %9
718-
%10 = load %3 : $*Builtin.Int32 // user: %12
719-
// function_ref use
720-
%11 = function_ref @use : $@convention(thin) (Builtin.Int32) -> () // user: %12
721-
%12 = apply %11(%10) : $@convention(thin) (Builtin.Int32) -> ()
722-
dealloc_stack %2#0 : $*@local_storage A // id: %13
723-
%14 = tuple () // user: %15
724-
return %14 : $()
725-
}
726-
727-
// Check load forwarding across strong_release in case the loaded memory does
728-
// not escape.
729-
// CHECK-LABEL: sil @test_load_forwarding_strong_release
730-
// CHECK: strong_release
731-
// CHECK-NOT: [[BOX0:%.*]] = load
732-
// CHECK: apply
733-
sil @test_load_forwarding_strong_release : $@convention(thin) (B, X) -> () {
734-
bb0(%0 : $B, %1 : $X):
735-
%2 = alloc_stack $A // users: %3, %12
736-
%3 = struct_element_addr %2#1 : $*A, #A.i // users: %4, %9
737-
%4 = load %3 : $*Builtin.Int32
738-
%5 = ref_to_unowned %0 : $B to $@sil_unowned B // user: %6
739-
unowned_release %5 : $@sil_unowned B // id: %6
740-
strong_release %0 : $B // id: %7
741-
release_value %1 : $X // id: %8
742-
%9 = load %3 : $*Builtin.Int32 // user: %11
743-
// function_ref use
744-
%10 = function_ref @use : $@convention(thin) (Builtin.Int32) -> () // user: %11
745-
%11 = apply %10(%9) : $@convention(thin) (Builtin.Int32) -> ()
746-
dealloc_stack %2#0 : $*@local_storage A // id: %12
747-
%13 = tuple () // user: %14
748-
return %13 : $() // id: %14
749-
}
750555

751556
typealias I32 = Builtin.Int32
752557

test/SILPasses/redundantloadelimination_basic.sil

Lines changed: 171 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ enum XYZ {
9191
sil @use : $@convention(thin) (Builtin.Int32) -> ()
9292
sil @use_64 : $@convention(thin) (Builtin.Int64) -> ()
9393
sil @use_2_64 : $@convention(thin) (Builtin.Int64, Builtin.Int64) -> ()
94-
sil @use_a : $@convention(thin) (@in A) -> ()
94+
sil @use_a : $@convention(thin) (A) -> ()
9595
sil @escaped_a_ptr : $@convention(thin) (@out A) -> ()
9696
sil @escaped_a : $@convention(thin) () -> Builtin.RawPointer
9797

@@ -466,3 +466,173 @@ bb5:
466466
return %2 : $Builtin.Int32
467467
}
468468

469+
470+
// CHECK-LABEL: sil @load_to_load_conflicting_branches_diamond : $@convention(thin) (@inout Builtin.Int32) -> () {
471+
// CHECK: bb0(
472+
// CHECK: load
473+
// CHECK: bb1:
474+
// CHECK-NOT: load
475+
// CHECK: store
476+
// CHECK-NOT: load
477+
// CHECK: bb2:
478+
// CHECK: bb3:
479+
// CHECK: load
480+
sil @load_to_load_conflicting_branches_diamond : $@convention(thin) (@inout Builtin.Int32) -> () {
481+
// %0 // users: %1, %4, %9, %11, %16, %21
482+
bb0(%0 : $*Builtin.Int32):
483+
%1 = load %0 : $*Builtin.Int32 // user: %2
484+
%2 = builtin "trunc_Int32_Int1"(%1 : $Builtin.Int32) : $Builtin.Int1
485+
cond_br undef, bb1, bb2 // id: %3
486+
487+
bb1: // Preds: bb0
488+
%4 = load %0 : $*Builtin.Int32 // users: %6, %8, %10
489+
// function_ref use
490+
%5 = function_ref @use : $@convention(thin) (Builtin.Int32) -> () // user: %6
491+
%6 = apply %5(%4) : $@convention(thin) (Builtin.Int32) -> ()
492+
%7 = integer_literal $Builtin.Int32, 2 // user: %9
493+
%8 = builtin "trunc_Int32_Int1"(%4 : $Builtin.Int32) : $Builtin.Int1
494+
store %7 to %0 : $*Builtin.Int32 // id: %9
495+
%10 = builtin "trunc_Int32_Int1"(%4 : $Builtin.Int32) : $Builtin.Int1
496+
%11 = load %0 : $*Builtin.Int32 // users: %13, %14
497+
// function_ref use
498+
%12 = function_ref @use : $@convention(thin) (Builtin.Int32) -> () // user: %13
499+
%13 = apply %12(%11) : $@convention(thin) (Builtin.Int32) -> ()
500+
%14 = builtin "trunc_Int32_Int1"(%11 : $Builtin.Int32) : $Builtin.Int1
501+
br bb3 // id: %15
502+
503+
bb2: // Preds: bb0
504+
%16 = load %0 : $*Builtin.Int32 // users: %18, %19
505+
// function_ref use
506+
%17 = function_ref @use : $@convention(thin) (Builtin.Int32) -> () // user: %18
507+
%18 = apply %17(%16) : $@convention(thin) (Builtin.Int32) -> ()
508+
%19 = builtin "trunc_Int32_Int1"(%16 : $Builtin.Int32) : $Builtin.Int1
509+
br bb3 // id: %20
510+
511+
bb3: // Preds: bb1 bb2
512+
%21 = load %0 : $*Builtin.Int32 // user: %23
513+
// function_ref use
514+
%22 = function_ref @use : $@convention(thin) (Builtin.Int32) -> () // user: %23
515+
%23 = apply %22(%21) : $@convention(thin) (Builtin.Int32) -> ()
516+
%24 = tuple () // user: %25
517+
return %24 : $() // id: %25
518+
}
519+
520+
// CHECK-LABEL: load_to_load_irreducible_loop
521+
// CHECK: bb0
522+
// CHECK: load
523+
// CHECK: bb1
524+
// CHECK-NOT: load
525+
// CHECK: store
526+
// CHECK: bb2
527+
// CHECK-NOT: load
528+
// CHECK: bb3
529+
// CHECK-NOT: load
530+
// CHECK: load
531+
sil @load_to_load_irreducible_loop : $@convention(thin) () -> () {
532+
bb0:
533+
%0 = alloc_stack $Int32
534+
%99 = struct_element_addr %0#1 : $*Int32, #Int32.value
535+
%1 = load %99 : $*Builtin.Int32
536+
builtin "trunc_Int32_Int1"(%1 : $Builtin.Int32) : $Builtin.Int1
537+
cond_br undef, bb1, bb2
538+
539+
bb1:
540+
%3 = load %99 : $*Builtin.Int32
541+
%4 = integer_literal $Builtin.Int32, 2
542+
%22 = function_ref @use : $@convention(thin) (Builtin.Int32) -> () // user: %23
543+
%23 = apply %22(%3) : $@convention(thin) (Builtin.Int32) -> ()
544+
store %4 to %99 : $*Builtin.Int32
545+
builtin "trunc_Int32_Int1"(%3 : $Builtin.Int32) : $Builtin.Int1
546+
%5 = load %99 : $*Builtin.Int32
547+
%24 = apply %22(%5) : $@convention(thin) (Builtin.Int32) -> ()
548+
builtin "trunc_Int32_Int1"(%5 : $Builtin.Int32) : $Builtin.Int1
549+
cond_br undef, bb2, bb3
550+
551+
bb2:
552+
%6 = load %99 : $*Builtin.Int32
553+
%25 = function_ref @use : $@convention(thin) (Builtin.Int32) -> () // user: %23
554+
%26 = apply %25(%6) : $@convention(thin) (Builtin.Int32) -> ()
555+
builtin "trunc_Int32_Int1"(%6 : $Builtin.Int32) : $Builtin.Int1
556+
cond_br undef, bb1, bb3
557+
558+
bb3:
559+
%7 = load %99 : $*Builtin.Int32
560+
%125 = function_ref @use : $@convention(thin) (Builtin.Int32) -> () // user: %23
561+
%126 = apply %125(%7) : $@convention(thin) (Builtin.Int32) -> ()
562+
builtin "trunc_Int32_Int1"(%7 : $Builtin.Int32) : $Builtin.Int1
563+
dealloc_stack %0#0 : $*@local_storage Int32
564+
%9999 = tuple()
565+
return %9999 : $()
566+
}
567+
568+
// CHECK-LABEL: load_to_load_loop
569+
// CHECK: bb1
570+
// CHECK-NOT: load
571+
// CHECK: cond_br
572+
// CHECK: bb2
573+
// CHECK-NOT: load
574+
// CHECK: return
575+
sil @load_to_load_loop : $@convention(thin) () -> () {
576+
bb0:
577+
%101 = alloc_stack $Int32
578+
%102 = alloc_stack $Int32
579+
%0 = struct_element_addr %101#1 : $*Int32, #Int32.value
580+
%1 = struct_element_addr %102#1 : $*Int32, #Int32.value
581+
%2 = load %0 : $*Builtin.Int32
582+
%99 = load %1 : $*Builtin.Int32
583+
%125 = function_ref @use : $@convention(thin) (Builtin.Int32) -> () // user: %23
584+
%126 = apply %125(%2) : $@convention(thin) (Builtin.Int32) -> ()
585+
%127 = apply %125(%99) : $@convention(thin) (Builtin.Int32) -> ()
586+
br bb1
587+
588+
bb1:
589+
%4 = load %0 : $*Builtin.Int32
590+
%5 = integer_literal $Builtin.Int32, 2
591+
%1125 = function_ref @use : $@convention(thin) (Builtin.Int32) -> () // user: %23
592+
%1126 = apply %1125(%4) : $@convention(thin) (Builtin.Int32) -> ()
593+
store %5 to %0 : $*Builtin.Int32
594+
builtin "trunc_Int32_Int1"(%4 : $Builtin.Int32) : $Builtin.Int1
595+
%6 = load %0 : $*Builtin.Int32
596+
%11125 = function_ref @use : $@convention(thin) (Builtin.Int32) -> () // user: %23
597+
%11126 = apply %11125(%6) : $@convention(thin) (Builtin.Int32) -> ()
598+
cond_br undef, bb1, bb2
599+
600+
bb2:
601+
%7 = load %0 : $*Builtin.Int32
602+
%111125 = function_ref @use : $@convention(thin) (Builtin.Int32) -> () // user: %23
603+
%111126 = apply %111125(%7) : $@convention(thin) (Builtin.Int32) -> ()
604+
dealloc_stack %102#0 : $*@local_storage Int32
605+
dealloc_stack %101#0 : $*@local_storage Int32
606+
%9999 = tuple()
607+
return %9999 : $()
608+
}
609+
610+
// Forward store %1 and store %2 such that load %3 becomes an identity trivial cast.
611+
// Both loads from %0 will be eliminated.
612+
// CHECK-LABEL: sil @test_read_dependence_allows_forwarding_multi_bb_2 : $@convention(thin) (@inout A, A, A) -> A {
613+
// CHECK: bb1
614+
// CHECK: load
615+
// CHECK-NOT: load
616+
// CHECK: bb2
617+
sil @test_read_dependence_allows_forwarding_multi_bb_2 : $@convention(thin) (@inout A, A, A) -> A {
618+
bb0(%0 : $*A, %1 : $A, %2 : $A):
619+
store %1 to %0 : $*A
620+
%3 = unchecked_addr_cast %0 : $*A to $*A
621+
%4 = unchecked_addr_cast %3 : $*A to $*A
622+
br bb1
623+
624+
bb1:
625+
// This means that the first store is not dead.
626+
%6 = load %3 : $*A
627+
%7 = load %0 : $*A
628+
%8 = load %0 : $*A
629+
%22 = function_ref @use_a : $@convention(thin) (A) -> ()
630+
%123 = apply %22(%6) : $@convention(thin) (A) -> ()
631+
%223 = apply %22(%7) : $@convention(thin) (A) -> ()
632+
%323 = apply %22(%8) : $@convention(thin) (A) -> ()
633+
store %2 to %0 : $*A
634+
cond_br undef, bb1, bb2
635+
636+
bb2:
637+
return %7 : $A
638+
}

0 commit comments

Comments
 (0)