[llvm] r276447 - Invariant start/end intrinsics overloaded for address space
Anna Thomas via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 22 10:49:40 PDT 2016
Author: annat
Date: Fri Jul 22 12:49:40 2016
New Revision: 276447
URL: http://llvm.org/viewvc/llvm-project?rev=276447&view=rev
Log:
Invariant start/end intrinsics overloaded for address space
Summary:
The llvm.invariant.start and llvm.invariant.end intrinsics currently
support specifying invariant memory objects only in the default address
space.
With this change, these intrinsics are overloaded for any adddress space
for memory objects
and we can use these llvm invariant intrinsics in non-default address
spaces.
Example: llvm.invariant.start.p1i8(i64 4, i8 addrspace(1)* %ptr)
This overloaded intrinsic is needed for representing final or invariant
memory in managed languages.
Reviewers: apilipenko, reames
Subscribers: llvm-commits
Modified:
llvm/trunk/docs/LangRef.rst
llvm/trunk/include/llvm/IR/Intrinsics.td
llvm/trunk/lib/IR/AutoUpgrade.cpp
llvm/trunk/test/Assembler/auto_upgrade_intrinsics.ll
llvm/trunk/test/CodeGen/AMDGPU/promote-alloca-invariant-markers.ll
llvm/trunk/test/Feature/memorymarkers.ll
llvm/trunk/test/Transforms/GlobalOpt/invariant-nodatalayout.ll
llvm/trunk/test/Transforms/GlobalOpt/invariant.ll
llvm/trunk/test/Transforms/InstCombine/invariant.ll
Modified: llvm/trunk/docs/LangRef.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LangRef.rst?rev=276447&r1=276446&r2=276447&view=diff
==============================================================================
--- llvm/trunk/docs/LangRef.rst (original)
+++ llvm/trunk/docs/LangRef.rst Fri Jul 22 12:49:40 2016
@@ -11842,10 +11842,11 @@ object following this intrinsic may be r
Syntax:
"""""""
+This is an overloaded intrinsic. The memory object can belong to any address space.
::
- declare {}* @llvm.invariant.start(i64 <size>, i8* nocapture <ptr>)
+ declare {}* @llvm.invariant.start.p0i8(i64 <size>, i8* nocapture <ptr>)
Overview:
"""""""""
@@ -11872,10 +11873,11 @@ unchanging.
Syntax:
"""""""
+This is an overloaded intrinsic. The memory object can belong to any address space.
::
- declare void @llvm.invariant.end({}* <start>, i64 <size>, i8* nocapture <ptr>)
+ declare void @llvm.invariant.end.p0i8({}* <start>, i64 <size>, i8* nocapture <ptr>)
Overview:
"""""""""
Modified: llvm/trunk/include/llvm/IR/Intrinsics.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Intrinsics.td?rev=276447&r1=276446&r2=276447&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Intrinsics.td (original)
+++ llvm/trunk/include/llvm/IR/Intrinsics.td Fri Jul 22 12:49:40 2016
@@ -554,11 +554,11 @@ def int_lifetime_end : Intrinsic<[],
[llvm_i64_ty, llvm_ptr_ty],
[IntrArgMemOnly, NoCapture<1>]>;
def int_invariant_start : Intrinsic<[llvm_descriptor_ty],
- [llvm_i64_ty, llvm_ptr_ty],
+ [llvm_i64_ty, llvm_anyptr_ty],
[IntrArgMemOnly, NoCapture<1>]>;
def int_invariant_end : Intrinsic<[],
[llvm_descriptor_ty, llvm_i64_ty,
- llvm_ptr_ty],
+ llvm_anyptr_ty],
[IntrArgMemOnly, NoCapture<2>]>;
def int_invariant_group_barrier : Intrinsic<[llvm_ptr_ty],
Modified: llvm/trunk/lib/IR/AutoUpgrade.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AutoUpgrade.cpp?rev=276447&r1=276446&r2=276447&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AutoUpgrade.cpp (original)
+++ llvm/trunk/lib/IR/AutoUpgrade.cpp Fri Jul 22 12:49:40 2016
@@ -148,7 +148,31 @@ static bool UpgradeIntrinsicFunction1(Fu
}
break;
}
-
+ case 'i': {
+ if (Name.startswith("invariant.start")) {
+ auto Args = F->getFunctionType()->params();
+ Type* ObjectPtr[1] = {Args[1]};
+ if (F->getName() !=
+ Intrinsic::getName(Intrinsic::invariant_start, ObjectPtr)) {
+ F->setName(Name + ".old");
+ NewFn = Intrinsic::getDeclaration(
+ F->getParent(), Intrinsic::invariant_start, ObjectPtr);
+ return true;
+ }
+ }
+ if (Name.startswith("invariant.end")) {
+ auto Args = F->getFunctionType()->params();
+ Type* ObjectPtr[1] = {Args[2]};
+ if (F->getName() !=
+ Intrinsic::getName(Intrinsic::invariant_end, ObjectPtr)) {
+ F->setName(Name + ".old");
+ NewFn = Intrinsic::getDeclaration(F->getParent(),
+ Intrinsic::invariant_end, ObjectPtr);
+ return true;
+ }
+ }
+ break;
+ }
case 'm': {
if (Name.startswith("masked.load.")) {
Type *Tys[] = { F->getReturnType(), F->arg_begin()->getType() };
@@ -1339,6 +1363,8 @@ void llvm::UpgradeIntrinsicCall(CallInst
return;
}
+ case Intrinsic::invariant_start:
+ case Intrinsic::invariant_end:
case Intrinsic::masked_load:
case Intrinsic::masked_store: {
SmallVector<Value *, 4> Args(CI->arg_operands().begin(),
Modified: llvm/trunk/test/Assembler/auto_upgrade_intrinsics.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/auto_upgrade_intrinsics.ll?rev=276447&r1=276446&r2=276447&view=diff
==============================================================================
--- llvm/trunk/test/Assembler/auto_upgrade_intrinsics.ll (original)
+++ llvm/trunk/test/Assembler/auto_upgrade_intrinsics.ll Fri Jul 22 12:49:40 2016
@@ -76,6 +76,21 @@ define void @tests.masked.store(<2 x dou
ret void
}
+
+declare {}* @llvm.invariant.start(i64, i8* nocapture) nounwind readonly
+declare void @llvm.invariant.end({}*, i64, i8* nocapture) nounwind
+
+define void @tests.invariant.start.end() {
+ ; CHECK-LABEL: @tests.invariant.start.end(
+ %a = alloca i8
+ %i = call {}* @llvm.invariant.start(i64 1, i8* %a)
+ ; CHECK: call {}* @llvm.invariant.start.p0i8
+ store i8 0, i8* %a
+ call void @llvm.invariant.end({}* %i, i64 1, i8* %a)
+ ; CHECK: call void @llvm.invariant.end.p0i8
+ ret void
+}
+
@__stack_chk_guard = external global i8*
declare void @llvm.stackprotectorcheck(i8**)
Modified: llvm/trunk/test/CodeGen/AMDGPU/promote-alloca-invariant-markers.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/promote-alloca-invariant-markers.ll?rev=276447&r1=276446&r2=276447&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/promote-alloca-invariant-markers.ll (original)
+++ llvm/trunk/test/CodeGen/AMDGPU/promote-alloca-invariant-markers.ll Fri Jul 22 12:49:40 2016
@@ -1,7 +1,7 @@
; RUN: llc -march=amdgcn -mattr=+promote-alloca -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s
-declare {}* @llvm.invariant.start(i64, i8* nocapture) #0
-declare void @llvm.invariant.end({}*, i64, i8* nocapture) #0
+declare {}* @llvm.invariant.start.p0i8(i64, i8* nocapture) #0
+declare void @llvm.invariant.end.p0i8({}*, i64, i8* nocapture) #0
declare i8* @llvm.invariant.group.barrier(i8*) #1
; GCN-LABEL: {{^}}use_invariant_promotable_lds:
@@ -14,8 +14,8 @@ bb:
%tmp2 = getelementptr inbounds i32, i32 addrspace(1)* %arg, i64 1
%tmp3 = load i32, i32 addrspace(1)* %tmp2
store i32 %tmp3, i32* %tmp
- %tmp4 = call {}* @llvm.invariant.start(i64 4, i8* %tmp1) #0
- call void @llvm.invariant.end({}* %tmp4, i64 4, i8* %tmp1) #0
+ %tmp4 = call {}* @llvm.invariant.start.p0i8(i64 4, i8* %tmp1) #0
+ call void @llvm.invariant.end.p0i8({}* %tmp4, i64 4, i8* %tmp1) #0
%tmp5 = call i8* @llvm.invariant.group.barrier(i8* %tmp1) #1
ret void
}
Modified: llvm/trunk/test/Feature/memorymarkers.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Feature/memorymarkers.ll?rev=276447&r1=276446&r2=276447&view=diff
==============================================================================
--- llvm/trunk/test/Feature/memorymarkers.ll (original)
+++ llvm/trunk/test/Feature/memorymarkers.ll Fri Jul 22 12:49:40 2016
@@ -6,8 +6,8 @@ declare void @_Z3barRKi(i32*)
declare void @llvm.lifetime.start(i64, i8* nocapture) nounwind
declare void @llvm.lifetime.end(i64, i8* nocapture) nounwind
-declare {}* @llvm.invariant.start(i64, i8* nocapture) readonly nounwind
-declare void @llvm.invariant.end({}*, i64, i8* nocapture) nounwind
+declare {}* @llvm.invariant.start.p0i8(i64, i8* nocapture) readonly nounwind
+declare void @llvm.invariant.end.p0i8({}*, i64, i8* nocapture) nounwind
define i32 @_Z4foo2v() nounwind {
entry:
@@ -24,12 +24,12 @@ entry:
store i32 5, i32* %1, align 4
;; Constructor has finished here.
- %inv = call {}* @llvm.invariant.start(i64 8, i8* %y)
+ %inv = call {}* @llvm.invariant.start.p0i8(i64 8, i8* %y)
call void @_Z3barRKi(i32* %0) nounwind
%2 = load i32, i32* %0, align 8
;; Destructor is run here.
- call void @llvm.invariant.end({}* %inv, i64 8, i8* %y)
+ call void @llvm.invariant.end.p0i8({}* %inv, i64 8, i8* %y)
;; Destructor is done here.
call void @llvm.lifetime.end(i64 8, i8* %y)
ret i32 %2
Modified: llvm/trunk/test/Transforms/GlobalOpt/invariant-nodatalayout.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/invariant-nodatalayout.ll?rev=276447&r1=276446&r2=276447&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/invariant-nodatalayout.ll (original)
+++ llvm/trunk/test/Transforms/GlobalOpt/invariant-nodatalayout.ll Fri Jul 22 12:49:40 2016
@@ -1,14 +1,14 @@
; RUN: opt -globalopt -S -o - < %s | FileCheck %s
; The check here is that it doesn't crash.
-declare {}* @llvm.invariant.start(i64 %size, i8* nocapture %ptr)
+declare {}* @llvm.invariant.start.p0i8(i64 %size, i8* nocapture %ptr)
@object1 = global { i32, i32 } zeroinitializer
; CHECK: @object1 = global { i32, i32 } zeroinitializer
define void @ctor1() {
%ptr = bitcast {i32, i32}* @object1 to i8*
- call {}* @llvm.invariant.start(i64 4, i8* %ptr)
+ call {}* @llvm.invariant.start.p0i8(i64 4, i8* %ptr)
ret void
}
Modified: llvm/trunk/test/Transforms/GlobalOpt/invariant.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/invariant.ll?rev=276447&r1=276446&r2=276447&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/invariant.ll (original)
+++ llvm/trunk/test/Transforms/GlobalOpt/invariant.ll Fri Jul 22 12:49:40 2016
@@ -3,10 +3,10 @@
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
-declare {}* @llvm.invariant.start(i64 %size, i8* nocapture %ptr)
+declare {}* @llvm.invariant.start.p0i8(i64 %size, i8* nocapture %ptr)
define void @test1(i8* %ptr) {
- call {}* @llvm.invariant.start(i64 4, i8* %ptr)
+ call {}* @llvm.invariant.start.p0i8(i64 4, i8* %ptr)
ret void
}
@@ -25,7 +25,7 @@ define void @ctor1() {
define void @ctor2() {
store i32 -1, i32* @object2
%A = bitcast i32* @object2 to i8*
- %B = call {}* @llvm.invariant.start(i64 4, i8* %A)
+ %B = call {}* @llvm.invariant.start.p0i8(i64 4, i8* %A)
%C = bitcast {}* %B to i8*
ret void
}
@@ -36,7 +36,7 @@ define void @ctor2() {
define void @ctor3() {
store i32 -1, i32* @object3
%A = bitcast i32* @object3 to i8*
- call {}* @llvm.invariant.start(i64 3, i8* %A)
+ call {}* @llvm.invariant.start.p0i8(i64 3, i8* %A)
ret void
}
@@ -46,7 +46,7 @@ define void @ctor3() {
define void @ctor4() {
store i32 -1, i32* @object4
%A = bitcast i32* @object4 to i8*
- call {}* @llvm.invariant.start(i64 -1, i8* %A)
+ call {}* @llvm.invariant.start.p0i8(i64 -1, i8* %A)
ret void
}
Modified: llvm/trunk/test/Transforms/InstCombine/invariant.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/invariant.ll?rev=276447&r1=276446&r2=276447&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/invariant.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/invariant.ll Fri Jul 22 12:49:40 2016
@@ -2,15 +2,27 @@
; RUN: opt < %s -instcombine -S | FileCheck %s
declare void @g(i8*)
+declare void @g_addr1(i8 addrspace(1)*)
-declare {}* @llvm.invariant.start(i64, i8* nocapture) nounwind readonly
+declare {}* @llvm.invariant.start.p0i8(i64, i8* nocapture) nounwind readonly
+declare {}* @llvm.invariant.start.p1i8(i64, i8 addrspace(1)* nocapture) nounwind readonly
define i8 @f() {
%a = alloca i8 ; <i8*> [#uses=4]
store i8 0, i8* %a
- %i = call {}* @llvm.invariant.start(i64 1, i8* %a) ; <{}*> [#uses=0]
- ; CHECK: call {}* @llvm.invariant.start
+ %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %a) ; <{}*> [#uses=0]
+ ; CHECK: call {}* @llvm.invariant.start.p0i8
call void @g(i8* %a)
%r = load i8, i8* %a ; <i8> [#uses=1]
ret i8 %r
}
+
+; make sure llvm.invariant.call in non-default addrspace are also not eliminated.
+define i8 @f_addrspace1(i8 addrspace(1)* %a) {
+ store i8 0, i8 addrspace(1)* %a
+ %i = call {}* @llvm.invariant.start.p1i8(i64 1, i8 addrspace(1)* %a) ; <{}*> [#uses=0]
+ ; CHECK: call {}* @llvm.invariant.start.p1i8
+ call void @g_addr1(i8 addrspace(1)* %a)
+ %r = load i8, i8 addrspace(1)* %a ; <i8> [#uses=1]
+ ret i8 %r
+}
More information about the llvm-commits
mailing list