diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -696,6 +696,7 @@ case Intrinsic::coro_subfn_addr: case Intrinsic::threadlocal_address: case Intrinsic::experimental_widenable_condition: + case Intrinsic::tbaa_fence: // These intrinsics don't actually represent code after lowering. return 0; } diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td --- a/llvm/include/llvm/IR/Intrinsics.td +++ b/llvm/include/llvm/IR/Intrinsics.td @@ -1233,6 +1233,11 @@ [LLVMMatchType<0>], [IntrSpeculatable, IntrNoMem, IntrWillReturn]>; +def int_tbaa_fence : DefaultAttrsIntrinsic<[llvm_ptr_ty], + [llvm_ptr_ty], + [IntrArgMemOnly, IntrWillReturn, + NoCapture>]>; + //===------------------------ Stackmap Intrinsics -------------------------===// // def int_experimental_stackmap : DefaultAttrsIntrinsic<[], diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -2354,6 +2354,12 @@ return optimizeGatherScatterInst(II, II->getArgOperand(0)); case Intrinsic::masked_scatter: return optimizeGatherScatterInst(II, II->getArgOperand(1)); + case Intrinsic::tbaa_fence: { + Value *ArgVal = II->getArgOperand(0); + replaceAllUsesWith(II, ArgVal, FreshBBs, IsHugeFunc); + II->eraseFromParent(); + return true; + } } SmallVector PtrOps; diff --git a/llvm/lib/CodeGen/IntrinsicLowering.cpp b/llvm/lib/CodeGen/IntrinsicLowering.cpp --- a/llvm/lib/CodeGen/IntrinsicLowering.cpp +++ b/llvm/lib/CodeGen/IntrinsicLowering.cpp @@ -444,6 +444,8 @@ case Intrinsic::lifetime_end: // Discard region information. break; + case Intrinsic::tbaa_fence: + CI->replaceAllUsesWith(CI->getArgOperand(0)); } assert(CI->use_empty() && diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp --- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -1352,7 +1352,8 @@ case Intrinsic::launder_invariant_group: case Intrinsic::strip_invariant_group: - case Intrinsic::expect: { + case Intrinsic::expect: + case Intrinsic::tbaa_fence: { Register ResultReg = getRegForValue(II->getArgOperand(0)); if (!ResultReg) return false; diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -6777,6 +6777,7 @@ case Intrinsic::ptr_annotation: case Intrinsic::launder_invariant_group: case Intrinsic::strip_invariant_group: + case Intrinsic::tbaa_fence: // Drop the intrinsic, but forward the value setValue(&I, getValue(I.getOperand(0))); return; diff --git a/llvm/test/Analysis/TypeBasedAliasAnalysis/tbaa-fence.ll b/llvm/test/Analysis/TypeBasedAliasAnalysis/tbaa-fence.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Analysis/TypeBasedAliasAnalysis/tbaa-fence.ll @@ -0,0 +1,22 @@ +; RUN: opt < %s -aa-pipeline=tbaa -passes=aa-eval -evaluate-aa-metadata \ +; RUN: -print-no-aliases -print-modref -disable-output 2>&1 | FileCheck %s + +declare ptr @llvm.tbaa.fence(ptr) + +define void @simple(ptr %p) { +entry: + ; CHECK-LABEL: simple + ; CHECK: NoAlias: %x = load i8, ptr %fenced, align 1, !tbaa !3 <-> store i8 1, ptr %p, align 1, !tbaa !0 + ; CHECK: Both ModRef: Ptr: i8* %p <-> %fenced = call ptr @llvm.tbaa.fence(ptr %p) + ; CHECK: Both ModRef: Ptr: i8* %fenced <-> %fenced = call ptr @llvm.tbaa.fence(ptr %p) + store i8 1, ptr %p, !tbaa !3 + %fenced = call ptr @llvm.tbaa.fence(ptr %p) + %x = load i8, ptr %fenced, !tbaa !4 + ret void +} + +!0 = !{!"root"} +!1 = !{!"type1", !0, i64 0} +!2 = !{!"type2", !0, i64 0} +!3 = !{!1, !1, i64 0, i64 1} +!4 = !{!2, !2, i64 0, i64 1} diff --git a/llvm/test/CodeGen/Generic/tbaa-fence.ll b/llvm/test/CodeGen/Generic/tbaa-fence.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/Generic/tbaa-fence.ll @@ -0,0 +1,8 @@ +; RUN: llc < %s + +declare ptr @llvm.tbaa.fence(ptr) + +define ptr @call_fence(ptr %p) { + %ret = call ptr @llvm.tbaa.fence(ptr %p) + ret ptr %ret +}