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 %s 2 3; We should be able to hoist loads in presence of read only calls and stores 4; that do not alias. 5 6; Since LICM uses the AST mechanism for alias analysis, we will clump 7; 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 memory 9; operations. 10 11declare void @foo(i64, ptr) readonly 12 13; hoist the load out with the n2-threshold 14; since it doesn't alias with the store. 15; default AST mechanism clumps all memory locations in one set because of the 16; readonly call 17define void @test1(ptr %ptr) { 18; CHECK-LABEL: @test1( 19; CHECK-LABEL: entry: 20; CHECK: %val = load i32, ptr %ptr 21; CHECK-LABEL: loop: 22entry: 23 br label %loop 24 25loop: 26 %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ] 27 %val = load i32, ptr %ptr 28 call void @foo(i64 4, ptr %ptr) 29 %p2 = getelementptr i32, ptr %ptr, i32 1 30 store volatile i32 0, ptr %p2 31 %x.inc = add i32 %x, %val 32 br label %loop 33} 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 %ptr 40; CHECK-LABEL: loop: 41entry: 42 br label %loop 43 44loop: 45 %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ] 46 %val = load i32, ptr %ptr 47 call void @foo(i64 4, ptr %ptr) 48 %x.inc = add i32 %x, %val 49 br label %loop 50} 51 52; cannot hoist load since not guaranteed to execute 53define void @test3(ptr %ptr) { 54; CHECK-LABEL: @test3( 55; CHECK-LABEL: entry: 56; CHECK-LABEL: loop: 57; CHECK: %val = load i32, ptr %ptr 58entry: 59 br label %loop 60 61loop: 62 %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ] 63 call void @foo(i64 4, ptr %ptr) 64 %val = load i32, ptr %ptr 65 %x.inc = add i32 %x, %val 66 br label %loop 67} 68