[llvm] 8609df7 - AMDGPU: Refine undef handling for llvm.amdgcn.class intrinsic

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 1 15:36:13 PDT 2023


Author: Matt Arsenault
Date: 2023-06-01T18:35:55-04:00
New Revision: 8609df7c6e91301af72080caab01b2edcef78b33

URL: https://github.com/llvm/llvm-project/commit/8609df7c6e91301af72080caab01b2edcef78b33
DIFF: https://github.com/llvm/llvm-project/commit/8609df7c6e91301af72080caab01b2edcef78b33.diff

LOG: AMDGPU: Refine undef handling for llvm.amdgcn.class intrinsic

This barely matters since 99% are converted to the generic intrinsic now,
and the only real difference is the target intrinsic supports a variable
test mask. Start propagating poison. Prefer folding to a defined result (false)
for an undef test mask. Propagate undef for the first operand.

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 e49a480c0ea46..56a43d7de31b8 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
@@ -460,14 +460,20 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
       return ⅈ
     }
 
-    // FIXME: Should propagate poison.
-    if (isa<UndefValue>(Src0))
-      return IC.replaceInstUsesWith(II, UndefValue::get(II.getType()));
+    // Propagate poison.
+    if (isa<PoisonValue>(Src0) || isa<PoisonValue>(Src1))
+      return IC.replaceInstUsesWith(II, PoisonValue::get(II.getType()));
 
-    if (isa<UndefValue>(Src1)) {
+    // llvm.amdgcn.class(_, undef) -> false
+    if (IC.getSimplifyQuery().isUndefValue(Src1))
       return IC.replaceInstUsesWith(II, ConstantInt::get(II.getType(), false));
-    }
 
+    // llvm.amdgcn.class(undef, mask) -> mask != 0
+    if (IC.getSimplifyQuery().isUndefValue(Src0)) {
+      Value *CmpMask = IC.Builder.CreateICmpNE(
+          Src1, ConstantInt::getNullValue(Src1->getType()));
+      return IC.replaceInstUsesWith(II, CmpMask);
+    }
     break;
   }
   case Intrinsic::amdgcn_cvt_pkrtz: {

diff  --git a/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll b/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
index 522fe70b157e2..3407b43d4b078 100644
--- a/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
+++ b/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
@@ -569,14 +569,14 @@ define i1 @test_class_undef_mask_f32(float %x) nounwind {
 
 define i1 @test_class_poison_poison_f32(float %x) nounwind {
 ; CHECK-LABEL: @test_class_poison_poison_f32(
-; CHECK-NEXT:    ret i1 undef
+; CHECK-NEXT:    ret i1 poison
 ;
   %val = call i1 @llvm.amdgcn.class.f32(float poison, i32 poison)
   ret i1 %val
 }
 define i1 @test_class_val_poison_f32(float %arg) nounwind {
 ; CHECK-LABEL: @test_class_val_poison_f32(
-; CHECK-NEXT:    ret i1 false
+; CHECK-NEXT:    ret i1 poison
 ;
   %val = call i1 @llvm.amdgcn.class.f32(float %arg, i32 poison)
   ret i1 %val
@@ -584,7 +584,7 @@ define i1 @test_class_val_poison_f32(float %arg) nounwind {
 
 define i1 @test_class_poison_val_f32(i32 %arg) nounwind {
 ; CHECK-LABEL: @test_class_poison_val_f32(
-; CHECK-NEXT:    ret i1 undef
+; CHECK-NEXT:    ret i1 poison
 ;
   %val = call i1 @llvm.amdgcn.class.f32(float poison, i32 %arg)
   ret i1 %val
@@ -639,6 +639,15 @@ define i1 @test_class_undef_val_f32() nounwind {
   ret i1 %val
 }
 
+define i1 @test_class_undef_val_f32_var(i32 %arg) nounwind {
+; CHECK-LABEL: @test_class_undef_val_f32_var(
+; CHECK-NEXT:    [[VAL:%.*]] = icmp ne i32 [[ARG:%.*]], 0
+; CHECK-NEXT:    ret i1 [[VAL]]
+;
+  %val = call i1 @llvm.amdgcn.class.f32(float undef, i32 %arg)
+  ret i1 %val
+}
+
 define i1 @test_class_val_undef_f32(float %arg) nounwind {
 ; CHECK-LABEL: @test_class_val_undef_f32(
 ; CHECK-NEXT:    ret i1 false
@@ -649,7 +658,7 @@ define i1 @test_class_val_undef_f32(float %arg) nounwind {
 
 define i1 @test_class_undef_undef_f32() nounwind {
 ; CHECK-LABEL: @test_class_undef_undef_f32(
-; CHECK-NEXT:    ret i1 undef
+; CHECK-NEXT:    ret i1 false
 ;
   %val = call i1 @llvm.amdgcn.class.f32(float undef, i32 undef)
   ret i1 %val


        


More information about the llvm-commits mailing list