84 lines · plain
1; RUN: opt -passes=called-value-propagation -S < %s | FileCheck %s2 3target triple = "aarch64"4 5 6; This test checks that we propagate the functions through arguments and attach7; !callees metadata to the call. Such metadata can enable optimizations of this8; code sequence.9;10; For example, the code below a illustrates a contrived sort-like algorithm11; that accepts a pointer to a comparison function. Since the indirect call to12; the comparison function has only two targets, the call can be promoted to two13; direct calls using an if-then-else. The loop can then be unswitched and the14; called functions inlined. This essentially produces two loops, once15; specialized for each comparison.16;17; CHECK: %tmp3 = call i1 %cmp(ptr %tmp1, ptr %tmp2), !callees ![[MD:[0-9]+]]18; CHECK: ![[MD]] = !{ptr @ugt, ptr @ule}19;20define void @test_argument(ptr %x, i64 %n, i1 %flag) {21entry:22 %tmp0 = sub i64 %n, 123 br i1 %flag, label %then, label %else24 25then:26 call void @arrange_data(ptr %x, i64 %tmp0, ptr @ugt)27 br label %merge28 29else:30 call void @arrange_data(ptr %x, i64 %tmp0, ptr @ule)31 br label %merge32 33merge:34 ret void35}36 37define internal void @arrange_data(ptr %x, i64 %n, ptr %cmp) {38entry:39 %tmp0 = icmp eq i64 %n, 140 br i1 %tmp0, label %merge, label %for.body41 42for.body:43 %i = phi i64 [ 0, %entry ], [ %i.next, %cmp.false ]44 %i.next = add nuw nsw i64 %i, 145 %tmp1 = getelementptr inbounds i64, ptr %x, i64 %i46 %tmp2 = getelementptr inbounds i64, ptr %x, i64 %i.next47 %tmp3 = call i1 %cmp(ptr %tmp1, ptr %tmp2)48 br i1 %tmp3, label %cmp.true, label %cmp.false49 50cmp.true:51 call void @swap(ptr %tmp1, ptr %tmp2)52 br label %cmp.false53 54cmp.false:55 %cond = icmp slt i64 %i.next, %n56 br i1 %cond, label %for.body, label %for.end57 58for.end:59 %tmp4 = sub i64 %n, 160 call void @arrange_data(ptr %x, i64 %tmp4, ptr %cmp)61 br label %merge62 63merge:64 ret void65}66 67define internal i1 @ugt(ptr %a, ptr %b) {68entry:69 %tmp0 = load i64, ptr %a70 %tmp1 = load i64, ptr %b71 %tmp2 = icmp ugt i64 %tmp0, %tmp172 ret i1 %tmp273}74 75define internal i1 @ule(ptr %a, ptr %b) {76entry:77 %tmp0 = load i64, ptr %a78 %tmp1 = load i64, ptr %b79 %tmp2 = icmp ule i64 %tmp0, %tmp180 ret i1 %tmp281}82 83declare void @swap(ptr, ptr)84