Index: include/llvm/IR/Intrinsics.td =================================================================== --- include/llvm/IR/Intrinsics.td +++ include/llvm/IR/Intrinsics.td @@ -331,13 +331,13 @@ def int_thread_pointer : Intrinsic<[llvm_ptr_ty], [], [IntrNoMem]>, GCCBuiltin<"__builtin_thread_pointer">; -// IntrArgMemOnly is more pessimistic than strictly necessary for prefetch, -// however it does conveniently prevent the prefetch from being reordered -// with respect to nearby accesses to the same memory. -def int_prefetch : Intrinsic<[], - [llvm_ptr_ty, llvm_i32_ty, llvm_i32_ty, - llvm_i32_ty], - [IntrArgMemOnly, NoCapture<0>]>; +// IntrArgMemOrArgMemOnly is a little more pessimistic than strictly necessary +// for prefetch, however it does conveniently prevent the prefetch from being +// reordered overly much with respect to nearby access to the same memory while +// not impeding optimization. +def int_prefetch + : Intrinsic<[], [ llvm_ptr_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty ], + [ IntrInaccessibleMemOrArgMemOnly, ReadOnly<0>, NoCapture<0> ]>; def int_pcmarker : Intrinsic<[], [llvm_i32_ty]>; def int_readcyclecounter : Intrinsic<[llvm_i64_ty]>; Index: test/Bitcode/compatibility-3.6.ll =================================================================== --- test/Bitcode/compatibility-3.6.ll +++ test/Bitcode/compatibility-3.6.ll @@ -981,7 +981,7 @@ ; CHECK: select <2 x i1> , <2 x i8> , <2 x i8> call void @f.nobuiltin() builtin - ; CHECK: call void @f.nobuiltin() #33 + ; CHECK: call void @f.nobuiltin() #34 call fastcc noalias i32* @f.noalias() noinline ; CHECK: call fastcc noalias i32* @f.noalias() #11 @@ -1183,7 +1183,8 @@ ; CHECK: attributes #30 = { argmemonly nounwind readonly } ; CHECK: attributes #31 = { argmemonly nounwind } ; CHECK: attributes #32 = { nounwind readonly } -; CHECK: attributes #33 = { builtin } +; CHECK: attributes #33 = { inaccessiblemem_or_argmemonly nounwind } +; CHECK: attributes #34 = { builtin } ;; Metadata Index: test/Bitcode/compatibility-3.7.ll =================================================================== --- test/Bitcode/compatibility-3.7.ll +++ test/Bitcode/compatibility-3.7.ll @@ -1022,7 +1022,7 @@ ; CHECK: select <2 x i1> , <2 x i8> , <2 x i8> call void @f.nobuiltin() builtin - ; CHECK: call void @f.nobuiltin() #36 + ; CHECK: call void @f.nobuiltin() #37 call fastcc noalias i32* @f.noalias() noinline ; CHECK: call fastcc noalias i32* @f.noalias() #12 @@ -1246,7 +1246,8 @@ ; CHECK: attributes #33 = { argmemonly nounwind readonly } ; CHECK: attributes #34 = { argmemonly nounwind } ; CHECK: attributes #35 = { nounwind readonly } -; CHECK: attributes #36 = { builtin } +; CHECK: attributes #36 = { inaccessiblemem_or_argmemonly nounwind } +; CHECK: attributes #37 = { builtin } ;; Metadata Index: test/Bitcode/compatibility-3.8.ll =================================================================== --- test/Bitcode/compatibility-3.8.ll +++ test/Bitcode/compatibility-3.8.ll @@ -1170,7 +1170,7 @@ ; CHECK: select <2 x i1> , <2 x i8> , <2 x i8> call void @f.nobuiltin() builtin - ; CHECK: call void @f.nobuiltin() #39 + ; CHECK: call void @f.nobuiltin() #40 call fastcc noalias i32* @f.noalias() noinline ; CHECK: call fastcc noalias i32* @f.noalias() #12 @@ -1556,7 +1556,8 @@ ; CHECK: attributes #36 = { argmemonly nounwind readonly } ; CHECK: attributes #37 = { argmemonly nounwind } ; CHECK: attributes #38 = { nounwind readonly } -; CHECK: attributes #39 = { builtin } +; CHECK: attributes #39 = { inaccessiblemem_or_argmemonly nounwind } +; CHECK: attributes #40 = { builtin } ;; Metadata Index: test/Bitcode/compatibility-3.9.ll =================================================================== --- test/Bitcode/compatibility-3.9.ll +++ test/Bitcode/compatibility-3.9.ll @@ -1241,7 +1241,7 @@ ; CHECK: select <2 x i1> , <2 x i8> , <2 x i8> call void @f.nobuiltin() builtin - ; CHECK: call void @f.nobuiltin() #40 + ; CHECK: call void @f.nobuiltin() #41 call fastcc noalias i32* @f.noalias() noinline ; CHECK: call fastcc noalias i32* @f.noalias() #12 @@ -1588,7 +1588,7 @@ } declare void @f.writeonly() writeonly -; CHECK: declare void @f.writeonly() #39 +; CHECK: declare void @f.writeonly() #40 ; CHECK: attributes #0 = { alignstack=4 } ; CHECK: attributes #1 = { alignstack=8 } @@ -1629,8 +1629,9 @@ ; CHECK: attributes #36 = { argmemonly nounwind readonly } ; CHECK: attributes #37 = { argmemonly nounwind } ; CHECK: attributes #38 = { nounwind readonly } -; CHECK: attributes #39 = { writeonly } -; CHECK: attributes #40 = { builtin } +; CHECK: attributes #39 = { inaccessiblemem_or_argmemonly nounwind } +; CHECK: attributes #40 = { writeonly } +; CHECK: attributes #41 = { builtin } ;; Metadata Index: test/Bitcode/compatibility-4.0.ll =================================================================== --- test/Bitcode/compatibility-4.0.ll +++ test/Bitcode/compatibility-4.0.ll @@ -1241,7 +1241,7 @@ ; CHECK: select <2 x i1> , <2 x i8> , <2 x i8> call void @f.nobuiltin() builtin - ; CHECK: call void @f.nobuiltin() #40 + ; CHECK: call void @f.nobuiltin() #41 call fastcc noalias i32* @f.noalias() noinline ; CHECK: call fastcc noalias i32* @f.noalias() #12 @@ -1606,7 +1606,7 @@ declare void @f.writeonly() writeonly -; CHECK: declare void @f.writeonly() #39 +; CHECK: declare void @f.writeonly() #40 ;; Constant Expressions @@ -1654,8 +1654,9 @@ ; CHECK: attributes #36 = { argmemonly nounwind readonly } ; CHECK: attributes #37 = { argmemonly nounwind } ; CHECK: attributes #38 = { nounwind readonly } -; CHECK: attributes #39 = { writeonly } -; CHECK: attributes #40 = { builtin } +; CHECK: attributes #39 = { inaccessiblemem_or_argmemonly nounwind } +; CHECK: attributes #40 = { writeonly } +; CHECK: attributes #41 = { builtin } ;; Metadata Index: test/Bitcode/compatibility.ll =================================================================== --- test/Bitcode/compatibility.ll +++ test/Bitcode/compatibility.ll @@ -1244,7 +1244,7 @@ ; CHECK: select <2 x i1> , <2 x i8> , <2 x i8> call void @f.nobuiltin() builtin - ; CHECK: call void @f.nobuiltin() #40 + ; CHECK: call void @f.nobuiltin() #41 call fastcc noalias i32* @f.noalias() noinline ; CHECK: call fastcc noalias i32* @f.noalias() #12 @@ -1609,7 +1609,7 @@ declare void @f.writeonly() writeonly -; CHECK: declare void @f.writeonly() #39 +; CHECK: declare void @f.writeonly() #40 ;; Constant Expressions @@ -1657,8 +1657,9 @@ ; CHECK: attributes #36 = { argmemonly nounwind readonly } ; CHECK: attributes #37 = { argmemonly nounwind } ; CHECK: attributes #38 = { nounwind readonly } -; CHECK: attributes #39 = { writeonly } -; CHECK: attributes #40 = { builtin } +; CHECK: attributes #39 = { inaccessiblemem_or_argmemonly nounwind } +; CHECK: attributes #40 = { writeonly } +; CHECK: attributes #41 = { builtin } ;; Metadata Index: test/Transforms/InstCombine/prefetch-load.ll =================================================================== --- /dev/null +++ test/Transforms/InstCombine/prefetch-load.ll @@ -0,0 +1,34 @@ +; RUN: opt < %s -instcombine -S | FileCheck %s + +%struct.C = type { %struct.C*, i32 } + +; Check that we instcombine the load across the prefetch. + +; CHECK-LABEL: define signext i32 @foo +define signext i32 @foo(%struct.C* %c) local_unnamed_addr #0 { +; CHECK: store i32 %dec, i32* %length_ +; CHECK-NOT: load +; CHECK: llvm.prefetch +; CHECK-NEXT: ret +entry: + %next_ = getelementptr inbounds %struct.C, %struct.C* %c, i32 0, i32 0 + %0 = load %struct.C*, %struct.C** %next_, align 8 + %next_1 = getelementptr inbounds %struct.C, %struct.C* %0, i32 0, i32 0 + %1 = load %struct.C*, %struct.C** %next_1, align 8 + store %struct.C* %1, %struct.C** %next_, align 8 + %length_ = getelementptr inbounds %struct.C, %struct.C* %c, i32 0, i32 1 + %2 = load i32, i32* %length_, align 8 + %dec = add nsw i32 %2, -1 + store i32 %dec, i32* %length_, align 8 + %3 = bitcast %struct.C* %1 to i8* + call void @llvm.prefetch(i8* %3, i32 0, i32 0, i32 1) + %4 = load i32, i32* %length_, align 8 + ret i32 %4 +} + +; Function Attrs: inaccessiblemem_or_argmemonly nounwind +declare void @llvm.prefetch(i8* nocapture readonly, i32, i32, i32) + +attributes #0 = { noinline nounwind } +; We've explicitly removed the function attrs from llvm.prefetch so we get the defaults. +; attributes #1 = { inaccessiblemem_or_argmemonly nounwind }