110 lines · plain
1; RUN: opt -mtriple=amdgcn-amd-amdhsa -passes=load-store-vectorizer -S -o - %s | FileCheck %s2; RUN: opt -mtriple=amdgcn-amd-amdhsa -aa-pipeline=basic-aa -passes='function(load-store-vectorizer)' -S -o - %s | FileCheck %s3 4; Check position of the inserted vector load/store. Vectorized loads should be5; inserted at the position of the first load in the chain, and stores should be6; inserted at the position of the last store.7 8; CHECK-LABEL: @insert_load_point(9; CHECK: %z = add i32 %x, 410; CHECK: load <2 x float>11; CHECK: %w = add i32 %y, 912; CHECK: %foo = add i32 %z, %w13define amdgpu_kernel void @insert_load_point(ptr addrspace(1) nocapture %a, ptr addrspace(1) nocapture %b, ptr addrspace(1) nocapture readonly %c, i64 %idx, i32 %x, i32 %y) #0 {14entry:15 %a.idx.x = getelementptr inbounds float, ptr addrspace(1) %a, i64 %idx16 %c.idx.x = getelementptr inbounds float, ptr addrspace(1) %c, i64 %idx17 %a.idx.x.1 = getelementptr inbounds float, ptr addrspace(1) %a.idx.x, i64 118 %c.idx.x.1 = getelementptr inbounds float, ptr addrspace(1) %c.idx.x, i64 119 20 %z = add i32 %x, 421 %ld.c = load float, ptr addrspace(1) %c.idx.x, align 422 %w = add i32 %y, 923 %ld.c.idx.1 = load float, ptr addrspace(1) %c.idx.x.1, align 424 %foo = add i32 %z, %w25 26 store float 0.0, ptr addrspace(1) %a.idx.x, align 427 store float 0.0, ptr addrspace(1) %a.idx.x.1, align 428 29 %add = fadd float %ld.c, %ld.c.idx.130 store float %add, ptr addrspace(1) %b, align 431 store i32 %foo, ptr addrspace(3) null, align 432 ret void33}34 35; CHECK-LABEL: @insert_store_point(36; CHECK: %z = add i32 %x, 437; CHECK: %w = add i32 %y, 938; CHECK: store <2 x float>39; CHECK: %foo = add i32 %z, %w40define amdgpu_kernel void @insert_store_point(ptr addrspace(1) nocapture %a, ptr addrspace(1) nocapture %b, ptr addrspace(1) nocapture readonly %c, i64 %idx, i32 %x, i32 %y) #0 {41entry:42 %a.idx.x = getelementptr inbounds float, ptr addrspace(1) %a, i64 %idx43 %c.idx.x = getelementptr inbounds float, ptr addrspace(1) %c, i64 %idx44 %a.idx.x.1 = getelementptr inbounds float, ptr addrspace(1) %a.idx.x, i64 145 %c.idx.x.1 = getelementptr inbounds float, ptr addrspace(1) %c.idx.x, i64 146 47 %ld.c = load float, ptr addrspace(1) %c.idx.x, align 448 %ld.c.idx.1 = load float, ptr addrspace(1) %c.idx.x.1, align 449 50 %z = add i32 %x, 451 store float 0.0, ptr addrspace(1) %a.idx.x, align 452 %w = add i32 %y, 953 store float 0.0, ptr addrspace(1) %a.idx.x.1, align 454 %foo = add i32 %z, %w55 56 %add = fadd float %ld.c, %ld.c.idx.157 store float %add, ptr addrspace(1) %b, align 458 store i32 %foo, ptr addrspace(3) null, align 459 ret void60}61 62; Here we have four stores, with an aliasing load before the last one. We can63; vectorize the first three stores as <3 x float>, but this vectorized store must64; be inserted at the location of the third scalar store, not the fourth one.65;66; CHECK-LABEL: @insert_store_point_alias67; CHECK: store <3 x float>68; CHECK: load float, ptr addrspace(1) %a.idx.269; CHECK: store float70; CHECK-SAME: %a.idx.371define float @insert_store_point_alias(ptr addrspace(1) nocapture %a, i64 %idx) {72 %a.idx = getelementptr inbounds float, ptr addrspace(1) %a, i64 %idx73 %a.idx.1 = getelementptr inbounds float, ptr addrspace(1) %a.idx, i64 174 %a.idx.2 = getelementptr inbounds float, ptr addrspace(1) %a.idx.1, i64 175 %a.idx.3 = getelementptr inbounds float, ptr addrspace(1) %a.idx.2, i64 176 77 store float 0.0, ptr addrspace(1) %a.idx, align 478 store float 0.0, ptr addrspace(1) %a.idx.1, align 479 store float 0.0, ptr addrspace(1) %a.idx.2, align 480 %x = load float, ptr addrspace(1) %a.idx.2, align 481 store float 0.0, ptr addrspace(1) %a.idx.3, align 482 83 ret float %x84}85 86; Here we have four stores, with an aliasing load before the last one. We can87; vectorize three of the stores before the load, but the important thing is that88; we *don't* sink the store to a[idx + 1] below the load.89;90; CHECK-LABEL: @insert_store_point_alias_ooo91; CHECK: store <3 x float>{{.*}} %a.idx.192; CHECK: load float, ptr addrspace(1) %a.idx.293; CHECK: store float{{.*}} %a.idx94define float @insert_store_point_alias_ooo(ptr addrspace(1) nocapture %a, i64 %idx) {95 %a.idx = getelementptr inbounds float, ptr addrspace(1) %a, i64 %idx96 %a.idx.1 = getelementptr inbounds float, ptr addrspace(1) %a.idx, i64 197 %a.idx.2 = getelementptr inbounds float, ptr addrspace(1) %a.idx.1, i64 198 %a.idx.3 = getelementptr inbounds float, ptr addrspace(1) %a.idx.2, i64 199 100 store float 0.0, ptr addrspace(1) %a.idx.3, align 4101 store float 0.0, ptr addrspace(1) %a.idx.1, align 4102 store float 0.0, ptr addrspace(1) %a.idx.2, align 4103 %x = load float, ptr addrspace(1) %a.idx.2, align 4104 store float 0.0, ptr addrspace(1) %a.idx, align 4105 106 ret float %x107}108 109attributes #0 = { nounwind }110