[llvm] a58541f - AMDGPU: Fold llvm.amdgcn.sqrt(undef)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 11 17:02:25 PST 2022


Author: Matt Arsenault
Date: 2022-11-11T17:02:19-08:00
New Revision: a58541f14d2d3e7d65f2e9b341bf2321b312c615

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

LOG: AMDGPU: Fold llvm.amdgcn.sqrt(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 d056d40886394..0895ae1a4fde0 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
@@ -379,6 +379,7 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
 
     break;
   }
+  case Intrinsic::amdgcn_sqrt:
   case Intrinsic::amdgcn_rsq: {
     Value *Src = II.getArgOperand(0);
 

diff  --git a/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll b/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
index 9504734343ca7..5df7c9049b382 100644
--- a/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
+++ b/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
@@ -73,6 +73,119 @@ define float @test_constant_fold_rcp_f32_43_strictfp() nounwind strictfp {
   ret float %val
 }
 
+; --------------------------------------------------------------------
+; llvm.amdgcn.sqrt
+; --------------------------------------------------------------------
+
+declare half @llvm.amdgcn.sqrt.f16(half) nounwind readnone
+declare float @llvm.amdgcn.sqrt.f32(float) nounwind readnone
+declare double @llvm.amdgcn.sqrt.f64(double) nounwind readnone
+
+define half @test_constant_fold_sqrt_f16_undef() nounwind {
+; CHECK-LABEL: @test_constant_fold_sqrt_f16_undef(
+; CHECK-NEXT:    ret half 0xH7E00
+;
+  %val = call half @llvm.amdgcn.sqrt.f16(half undef) nounwind readnone
+  ret half %val
+}
+
+define float @test_constant_fold_sqrt_f32_undef() nounwind {
+; CHECK-LABEL: @test_constant_fold_sqrt_f32_undef(
+; CHECK-NEXT:    ret float 0x7FF8000000000000
+;
+  %val = call float @llvm.amdgcn.sqrt.f32(float undef) nounwind readnone
+  ret float %val
+}
+
+define double @test_constant_fold_sqrt_f64_undef() nounwind {
+; CHECK-LABEL: @test_constant_fold_sqrt_f64_undef(
+; CHECK-NEXT:    ret double 0x7FF8000000000000
+;
+  %val = call double @llvm.amdgcn.sqrt.f64(double undef) nounwind readnone
+  ret double %val
+}
+
+define half @test_constant_fold_sqrt_f16_0() nounwind {
+; CHECK-LABEL: @test_constant_fold_sqrt_f16_0(
+; CHECK-NEXT:    [[VAL:%.*]] = call half @llvm.amdgcn.sqrt.f16(half 0xH0000) #[[ATTR15:[0-9]+]]
+; CHECK-NEXT:    ret half [[VAL]]
+;
+  %val = call half @llvm.amdgcn.sqrt.f16(half 0.0) nounwind readnone
+  ret half %val
+}
+
+define float @test_constant_fold_sqrt_f32_0() nounwind {
+; CHECK-LABEL: @test_constant_fold_sqrt_f32_0(
+; CHECK-NEXT:    [[VAL:%.*]] = call float @llvm.amdgcn.sqrt.f32(float 0.000000e+00) #[[ATTR15]]
+; CHECK-NEXT:    ret float [[VAL]]
+;
+  %val = call float @llvm.amdgcn.sqrt.f32(float 0.0) nounwind readnone
+  ret float %val
+}
+
+define double @test_constant_fold_sqrt_f64_0() nounwind {
+; CHECK-LABEL: @test_constant_fold_sqrt_f64_0(
+; CHECK-NEXT:    [[VAL:%.*]] = call double @llvm.amdgcn.sqrt.f64(double 0.000000e+00) #[[ATTR15]]
+; CHECK-NEXT:    ret double [[VAL]]
+;
+  %val = call double @llvm.amdgcn.sqrt.f64(double 0.0) nounwind readnone
+  ret double %val
+}
+
+define half @test_constant_fold_sqrt_f16_neg0() nounwind {
+; CHECK-LABEL: @test_constant_fold_sqrt_f16_neg0(
+; CHECK-NEXT:    [[VAL:%.*]] = call half @llvm.amdgcn.sqrt.f16(half 0xH8000) #[[ATTR15]]
+; CHECK-NEXT:    ret half [[VAL]]
+;
+  %val = call half @llvm.amdgcn.sqrt.f16(half -0.0) nounwind readnone
+  ret half %val
+}
+
+define float @test_constant_fold_sqrt_f32_neg0() nounwind {
+; CHECK-LABEL: @test_constant_fold_sqrt_f32_neg0(
+; CHECK-NEXT:    [[VAL:%.*]] = call float @llvm.amdgcn.sqrt.f32(float -0.000000e+00) #[[ATTR15]]
+; CHECK-NEXT:    ret float [[VAL]]
+;
+  %val = call float @llvm.amdgcn.sqrt.f32(float -0.0) nounwind readnone
+  ret float %val
+}
+
+define double @test_constant_fold_sqrt_f64_neg0() nounwind {
+; CHECK-LABEL: @test_constant_fold_sqrt_f64_neg0(
+; CHECK-NEXT:    [[VAL:%.*]] = call double @llvm.amdgcn.sqrt.f64(double -0.000000e+00) #[[ATTR15]]
+; CHECK-NEXT:    ret double [[VAL]]
+;
+  %val = call double @llvm.amdgcn.sqrt.f64(double -0.0) nounwind readnone
+  ret double %val
+}
+
+define double @test_constant_fold_sqrt_snan_f64() nounwind {
+; CHECK-LABEL: @test_constant_fold_sqrt_snan_f64(
+; CHECK-NEXT:    [[VAL:%.*]] = call double @llvm.amdgcn.sqrt.f64(double 0x7FF0000000000001)
+; CHECK-NEXT:    ret double [[VAL]]
+;
+  %val = call double @llvm.amdgcn.sqrt.f64(double 0x7FF0000000000001)
+  ret double %val
+}
+
+define double @test_constant_fold_sqrt_qnan_f64() nounwind {
+; CHECK-LABEL: @test_constant_fold_sqrt_qnan_f64(
+; CHECK-NEXT:    [[VAL:%.*]] = call double @llvm.amdgcn.sqrt.f64(double 0x7FF8000000000000)
+; CHECK-NEXT:    ret double [[VAL]]
+;
+  %val = call double @llvm.amdgcn.sqrt.f64(double 0x7FF8000000000000)
+  ret double %val
+}
+
+define double @test_constant_fold_sqrt_neg1() nounwind {
+; CHECK-LABEL: @test_constant_fold_sqrt_neg1(
+; CHECK-NEXT:    [[VAL:%.*]] = call double @llvm.amdgcn.sqrt.f64(double -1.000000e+00)
+; CHECK-NEXT:    ret double [[VAL]]
+;
+  %val = call double @llvm.amdgcn.sqrt.f64(double -1.0)
+  ret double %val
+}
+
 ; --------------------------------------------------------------------
 ; llvm.amdgcn.rsq
 ; --------------------------------------------------------------------


        


More information about the llvm-commits mailing list