[llvm] r264943 - AMDGPU: Constant folding for frexp_mant
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 30 15:28:26 PDT 2016
Author: arsenm
Date: Wed Mar 30 17:28:26 2016
New Revision: 264943
URL: http://llvm.org/viewvc/llvm-project?rev=264943&view=rev
Log:
AMDGPU: Constant folding for frexp_mant
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/trunk/test/Transforms/InstCombine/amdgcn-intrinsics.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=264943&r1=264942&r2=264943&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Wed Mar 30 17:28:26 2016
@@ -1846,6 +1846,20 @@ Instruction *InstCombiner::visitCallInst
break;
}
+ case Intrinsic::amdgcn_frexp_mant: {
+ Value *Src = II->getArgOperand(0);
+ if (const ConstantFP *C = dyn_cast<ConstantFP>(Src)) {
+ int Exp;
+ APFloat Significand = frexp(C->getValueAPF(), Exp,
+ APFloat::rmNearestTiesToEven);
+
+ return replaceInstUsesWith(CI, ConstantFP::get(II->getContext(),
+ Significand));
+ } else if (isa<UndefValue>(Src))
+ return replaceInstUsesWith(CI, Src);
+
+ break;
+ }
case Intrinsic::stackrestore: {
// If the save is right next to the restore, remove the restore. This can
// happen when variable allocas are DCE'd.
Modified: llvm/trunk/test/Transforms/InstCombine/amdgcn-intrinsics.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/amdgcn-intrinsics.ll?rev=264943&r1=264942&r2=264943&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/amdgcn-intrinsics.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/amdgcn-intrinsics.ll Wed Mar 30 17:28:26 2016
@@ -1,8 +1,13 @@
; RUN: opt -instcombine -S < %s | FileCheck %s
+; --------------------------------------------------------------------
+; llvm.amdgcn.rcp
+; --------------------------------------------------------------------
+
declare float @llvm.amdgcn.rcp.f32(float) nounwind readnone
declare double @llvm.amdgcn.rcp.f64(double) nounwind readnone
+
; CHECK-LABEL: @test_constant_fold_rcp_f32_1
; CHECK-NEXT: ret float 1.000000e+00
define float @test_constant_fold_rcp_f32_1() nounwind {
@@ -45,3 +50,153 @@ define double @test_constant_fold_rcp_f6
ret double %val
}
+
+; --------------------------------------------------------------------
+; llvm.amdgcn.frexp.mant
+; --------------------------------------------------------------------
+
+declare float @llvm.amdgcn.frexp.mant.f32(float) nounwind readnone
+declare double @llvm.amdgcn.frexp.mant.f64(double) nounwind readnone
+
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_undef(
+; CHECK-NEXT: ret float undef
+define float @test_constant_fold_frexp_mant_f32_undef() nounwind {
+ %val = call float @llvm.amdgcn.frexp.mant.f32(float undef)
+ ret float %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_undef(
+; CHECK-NEXT: ret double undef
+define double @test_constant_fold_frexp_mant_f64_undef() nounwind {
+ %val = call double @llvm.amdgcn.frexp.mant.f64(double undef)
+ ret double %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_0(
+; CHECK-NEXT: ret float 0.000000e+00
+define float @test_constant_fold_frexp_mant_f32_0() nounwind {
+ %val = call float @llvm.amdgcn.frexp.mant.f32(float 0.0)
+ ret float %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_0(
+; CHECK-NEXT: ret double 0.000000e+00
+define double @test_constant_fold_frexp_mant_f64_0() nounwind {
+ %val = call double @llvm.amdgcn.frexp.mant.f64(double 0.0)
+ ret double %val
+}
+
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_n0(
+; CHECK-NEXT: ret float -0.000000e+00
+define float @test_constant_fold_frexp_mant_f32_n0() nounwind {
+ %val = call float @llvm.amdgcn.frexp.mant.f32(float -0.0)
+ ret float %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_n0(
+; CHECK-NEXT: ret double -0.000000e+00
+define double @test_constant_fold_frexp_mant_f64_n0() nounwind {
+ %val = call double @llvm.amdgcn.frexp.mant.f64(double -0.0)
+ ret double %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_1(
+; CHECK-NEXT: ret float 5.000000e-01
+define float @test_constant_fold_frexp_mant_f32_1() nounwind {
+ %val = call float @llvm.amdgcn.frexp.mant.f32(float 1.0)
+ ret float %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_1(
+; CHECK-NEXT: ret double 5.000000e-01
+define double @test_constant_fold_frexp_mant_f64_1() nounwind {
+ %val = call double @llvm.amdgcn.frexp.mant.f64(double 1.0)
+ ret double %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_n1(
+; CHECK-NEXT: ret float -5.000000e-01
+define float @test_constant_fold_frexp_mant_f32_n1() nounwind {
+ %val = call float @llvm.amdgcn.frexp.mant.f32(float -1.0)
+ ret float %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_n1(
+; CHECK-NEXT: ret double -5.000000e-01
+define double @test_constant_fold_frexp_mant_f64_n1() nounwind {
+ %val = call double @llvm.amdgcn.frexp.mant.f64(double -1.0)
+ ret double %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_nan(
+; CHECK-NEXT: ret float 0x7FF8000000000000
+define float @test_constant_fold_frexp_mant_f32_nan() nounwind {
+ %val = call float @llvm.amdgcn.frexp.mant.f32(float 0x7FF8000000000000)
+ ret float %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_nan(
+; CHECK-NEXT: ret double 0x7FF8000000000000
+define double @test_constant_fold_frexp_mant_f64_nan() nounwind {
+ %val = call double @llvm.amdgcn.frexp.mant.f64(double 0x7FF8000000000000)
+ ret double %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_inf(
+; CHECK-NEXT: ret float 0x7FF0000000000000
+define float @test_constant_fold_frexp_mant_f32_inf() nounwind {
+ %val = call float @llvm.amdgcn.frexp.mant.f32(float 0x7FF0000000000000)
+ ret float %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_inf(
+; CHECK-NEXT: ret double 0x7FF0000000000000
+define double @test_constant_fold_frexp_mant_f64_inf() nounwind {
+ %val = call double @llvm.amdgcn.frexp.mant.f64(double 0x7FF0000000000000)
+ ret double %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_ninf(
+; CHECK-NEXT: ret float 0xFFF0000000000000
+define float @test_constant_fold_frexp_mant_f32_ninf() nounwind {
+ %val = call float @llvm.amdgcn.frexp.mant.f32(float 0xFFF0000000000000)
+ ret float %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_ninf(
+; CHECK-NEXT: ret double 0xFFF0000000000000
+define double @test_constant_fold_frexp_mant_f64_ninf() nounwind {
+ %val = call double @llvm.amdgcn.frexp.mant.f64(double 0xFFF0000000000000)
+ ret double %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_max_num(
+; CHECK-NEXT: ret float 0x3FEFFFFFE0000000
+define float @test_constant_fold_frexp_mant_f32_max_num() nounwind {
+ %val = call float @llvm.amdgcn.frexp.mant.f32(float 0x47EFFFFFE0000000)
+ ret float %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_max_num(
+; CHECK-NEXT: ret double 0x3FEFFFFFFFFFFFFF
+define double @test_constant_fold_frexp_mant_f64_max_num() nounwind {
+ %val = call double @llvm.amdgcn.frexp.mant.f64(double 0x7FEFFFFFFFFFFFFF)
+ ret double %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_min_num(
+; CHECK-NEXT: ret float 5.000000e-01
+define float @test_constant_fold_frexp_mant_f32_min_num() nounwind {
+ %val = call float @llvm.amdgcn.frexp.mant.f32(float 0x36A0000000000000)
+ ret float %val
+}
+
+; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_min_num(
+; CHECK-NEXT: ret double 5.000000e-01
+define double @test_constant_fold_frexp_mant_f64_min_num() nounwind {
+ %val = call double @llvm.amdgcn.frexp.mant.f64(double 4.940656e-324)
+ ret double %val
+}
+
More information about the llvm-commits
mailing list