[llvm] 45f16ea - AMDGPU: Combine is.shared/is.private of null/undef

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 15 15:20:57 PST 2021


Author: Matt Arsenault
Date: 2021-12-15T18:20:49-05:00
New Revision: 45f16eabd67b1d3f8fab3ed24c74b9b9dac2239e

URL: https://github.com/llvm/llvm-project/commit/45f16eabd67b1d3f8fab3ed24c74b9b9dac2239e
DIFF: https://github.com/llvm/llvm-project/commit/45f16eabd67b1d3f8fab3ed24c74b9b9dac2239e.diff

LOG: AMDGPU: Combine is.shared/is.private of null/undef

Added: 
    

Modified: 
    llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
    llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
index 88b4ec53a2a0d..db84b87669241 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
@@ -892,6 +892,15 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
     }
     break;
   }
+  case Intrinsic::amdgcn_is_shared:
+  case Intrinsic::amdgcn_is_private: {
+    if (isa<UndefValue>(II.getArgOperand(0)))
+      return IC.replaceInstUsesWith(II, UndefValue::get(II.getType()));
+
+    if (isa<ConstantPointerNull>(II.getArgOperand(0)))
+      return IC.replaceInstUsesWith(II, ConstantInt::getFalse(II.getType()));
+    break;
+  }
   default: {
     if (const AMDGPU::ImageDimIntrinsicInfo *ImageDimIntr =
             AMDGPU::getImageDimIntrinsicInfo(II.getIntrinsicID())) {

diff  --git a/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll b/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
index 358acbae49754..b9fba55e5026b 100644
--- a/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
+++ b/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
@@ -3922,3 +3922,47 @@ define amdgpu_kernel void @image_sample_a16_2darray_nnan(<4 x float> addrspace(1
   store <4 x float> %res, <4 x float> addrspace(1)* %out
   ret void
 }
+
+; --------------------------------------------------------------------
+; llvm.amdgcn.is.shared
+; --------------------------------------------------------------------
+
+declare i1 @llvm.amdgcn.is.shared(i8*) nounwind readnone
+
+define i1 @test_is_shared_null() nounwind {
+; CHECK-LABEL: @test_is_shared_null(
+; CHECK-NEXT:    ret i1 false
+;
+  %val = call i1 @llvm.amdgcn.is.shared(i8* null)
+  ret i1 %val
+}
+
+define i1 @test_is_shared_undef() nounwind {
+; CHECK-LABEL: @test_is_shared_undef(
+; CHECK-NEXT:    ret i1 undef
+;
+  %val = call i1 @llvm.amdgcn.is.shared(i8* undef)
+  ret i1 %val
+}
+
+; --------------------------------------------------------------------
+; llvm.amdgcn.is.private
+; --------------------------------------------------------------------
+
+declare i1 @llvm.amdgcn.is.private(i8*) nounwind readnone
+
+define i1 @test_is_private_null() nounwind {
+; CHECK-LABEL: @test_is_private_null(
+; CHECK-NEXT:    ret i1 false
+;
+  %val = call i1 @llvm.amdgcn.is.private(i8* null)
+  ret i1 %val
+}
+
+define i1 @test_is_private_undef() nounwind {
+; CHECK-LABEL: @test_is_private_undef(
+; CHECK-NEXT:    ret i1 undef
+;
+  %val = call i1 @llvm.amdgcn.is.private(i8* undef)
+  ret i1 %val
+}


        


More information about the llvm-commits mailing list