68 lines · plain
1; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<target-ir>,require<scalar-evolution>,require<opt-remark-emit>,loop-mssa(licm)' < %s -S | FileCheck %s2 3; We should be able to hoist loads in presence of read only calls and stores4; that do not alias.5 6; Since LICM uses the AST mechanism for alias analysis, we will clump7; together all loads and stores in one set along with the read-only call.8; This prevents hoisting load that doesn't alias with any other memory9; operations.10 11declare void @foo(i64, ptr) readonly12 13; hoist the load out with the n2-threshold14; since it doesn't alias with the store.15; default AST mechanism clumps all memory locations in one set because of the16; readonly call17define void @test1(ptr %ptr) {18; CHECK-LABEL: @test1(19; CHECK-LABEL: entry:20; CHECK: %val = load i32, ptr %ptr21; CHECK-LABEL: loop:22entry:23 br label %loop24 25loop:26 %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]27 %val = load i32, ptr %ptr28 call void @foo(i64 4, ptr %ptr)29 %p2 = getelementptr i32, ptr %ptr, i32 130 store volatile i32 0, ptr %p231 %x.inc = add i32 %x, %val32 br label %loop33}34 35; can hoist out load with the default AST and the alias analysis mechanism.36define void @test2(ptr %ptr) {37; CHECK-LABEL: @test2(38; CHECK-LABEL: entry:39; CHECK: %val = load i32, ptr %ptr40; CHECK-LABEL: loop:41entry:42 br label %loop43 44loop:45 %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]46 %val = load i32, ptr %ptr47 call void @foo(i64 4, ptr %ptr)48 %x.inc = add i32 %x, %val49 br label %loop50}51 52; cannot hoist load since not guaranteed to execute53define void @test3(ptr %ptr) {54; CHECK-LABEL: @test3(55; CHECK-LABEL: entry:56; CHECK-LABEL: loop:57; CHECK: %val = load i32, ptr %ptr58entry:59 br label %loop60 61loop:62 %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]63 call void @foo(i64 4, ptr %ptr)64 %val = load i32, ptr %ptr65 %x.inc = add i32 %x, %val66 br label %loop67}68