[llvm] r293582 - InferAddressSpaces: Don't replace volatile users
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 30 17:30:16 PST 2017
Author: arsenm
Date: Mon Jan 30 19:30:16 2017
New Revision: 293582
URL: http://llvm.org/viewvc/llvm-project?rev=293582&view=rev
Log:
InferAddressSpaces: Don't replace volatile users
Added:
llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/volatile.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp?rev=293582&r1=293581&r2=293582&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp Mon Jan 30 19:30:16 2017
@@ -570,8 +570,11 @@ bool InferAddressSpaces::rewriteWithNewA
<< "\n with\n " << *NewV << '\n');
for (Use *U : Uses) {
- if (isa<LoadInst>(U->getUser()) ||
- (isa<StoreInst>(U->getUser()) &&
+ LoadInst *LI = dyn_cast<LoadInst>(U->getUser());
+ StoreInst *SI = dyn_cast<StoreInst>(U->getUser());
+
+ if ((LI && !LI->isVolatile()) ||
+ (SI && !SI->isVolatile() &&
U->getOperandNo() == StoreInst::getPointerOperandIndex())) {
// If V is used as the pointer operand of a load/store, sets the pointer
// operand to NewV. This replacement does not change the element type,
Added: llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/volatile.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/volatile.ll?rev=293582&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/volatile.ll (added)
+++ llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/volatile.ll Mon Jan 30 19:30:16 2017
@@ -0,0 +1,82 @@
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -infer-address-spaces %s | FileCheck %s
+
+; Check that volatile users of addrspacecast are not replaced.
+
+; CHECK-LABEL: @volatile_load_flat_from_global(
+; CHECK: load volatile i32, i32 addrspace(4)*
+; CHECK: store i32 %val, i32 addrspace(1)*
+define void @volatile_load_flat_from_global(i32 addrspace(1)* nocapture %input, i32 addrspace(1)* nocapture %output) #0 {
+ %tmp0 = addrspacecast i32 addrspace(1)* %input to i32 addrspace(4)*
+ %tmp1 = addrspacecast i32 addrspace(1)* %output to i32 addrspace(4)*
+ %val = load volatile i32, i32 addrspace(4)* %tmp0, align 4
+ store i32 %val, i32 addrspace(4)* %tmp1, align 4
+ ret void
+}
+
+; CHECK-LABEL: @volatile_load_flat_from_constant(
+; CHECK: load volatile i32, i32 addrspace(4)*
+; CHECK: store i32 %val, i32 addrspace(1)*
+define void @volatile_load_flat_from_constant(i32 addrspace(2)* nocapture %input, i32 addrspace(1)* nocapture %output) #0 {
+ %tmp0 = addrspacecast i32 addrspace(2)* %input to i32 addrspace(4)*
+ %tmp1 = addrspacecast i32 addrspace(1)* %output to i32 addrspace(4)*
+ %val = load volatile i32, i32 addrspace(4)* %tmp0, align 4
+ store i32 %val, i32 addrspace(4)* %tmp1, align 4
+ ret void
+}
+
+; CHECK-LABEL: @volatile_load_flat_from_group(
+; CHECK: load volatile i32, i32 addrspace(4)*
+; CHECK: store i32 %val, i32 addrspace(3)*
+define void @volatile_load_flat_from_group(i32 addrspace(3)* nocapture %input, i32 addrspace(3)* nocapture %output) #0 {
+ %tmp0 = addrspacecast i32 addrspace(3)* %input to i32 addrspace(4)*
+ %tmp1 = addrspacecast i32 addrspace(3)* %output to i32 addrspace(4)*
+ %val = load volatile i32, i32 addrspace(4)* %tmp0, align 4
+ store i32 %val, i32 addrspace(4)* %tmp1, align 4
+ ret void
+}
+
+; CHECK-LABEL: @volatile_load_flat_from_private(
+; CHECK: load volatile i32, i32 addrspace(4)*
+; CHECK: store i32 %val, i32*
+define void @volatile_load_flat_from_private(i32* nocapture %input, i32* nocapture %output) #0 {
+ %tmp0 = addrspacecast i32* %input to i32 addrspace(4)*
+ %tmp1 = addrspacecast i32* %output to i32 addrspace(4)*
+ %val = load volatile i32, i32 addrspace(4)* %tmp0, align 4
+ store i32 %val, i32 addrspace(4)* %tmp1, align 4
+ ret void
+}
+
+; CHECK-LABEL: @volatile_store_flat_to_global(
+; CHECK: load i32, i32 addrspace(1)*
+; CHECK: store volatile i32 %val, i32 addrspace(4)*
+define void @volatile_store_flat_to_global(i32 addrspace(1)* nocapture %input, i32 addrspace(1)* nocapture %output) #0 {
+ %tmp0 = addrspacecast i32 addrspace(1)* %input to i32 addrspace(4)*
+ %tmp1 = addrspacecast i32 addrspace(1)* %output to i32 addrspace(4)*
+ %val = load i32, i32 addrspace(4)* %tmp0, align 4
+ store volatile i32 %val, i32 addrspace(4)* %tmp1, align 4
+ ret void
+}
+
+; CHECK-LABEL: @volatile_store_flat_to_group(
+; CHECK: load i32, i32 addrspace(3)*
+; CHECK: store volatile i32 %val, i32 addrspace(4)*
+define void @volatile_store_flat_to_group(i32 addrspace(3)* nocapture %input, i32 addrspace(3)* nocapture %output) #0 {
+ %tmp0 = addrspacecast i32 addrspace(3)* %input to i32 addrspace(4)*
+ %tmp1 = addrspacecast i32 addrspace(3)* %output to i32 addrspace(4)*
+ %val = load i32, i32 addrspace(4)* %tmp0, align 4
+ store volatile i32 %val, i32 addrspace(4)* %tmp1, align 4
+ ret void
+}
+
+; CHECK-LABEL: @volatile_store_flat_to_private(
+; CHECK: load i32, i32*
+; CHECK: store volatile i32 %val, i32 addrspace(4)*
+define void @volatile_store_flat_to_private(i32* nocapture %input, i32* nocapture %output) #0 {
+ %tmp0 = addrspacecast i32* %input to i32 addrspace(4)*
+ %tmp1 = addrspacecast i32* %output to i32 addrspace(4)*
+ %val = load i32, i32 addrspace(4)* %tmp0, align 4
+ store volatile i32 %val, i32 addrspace(4)* %tmp1, align 4
+ ret void
+}
+
+attributes #0 = { nounwind }
\ No newline at end of file
More information about the llvm-commits
mailing list