From: Matt Arsenault Date: Fri, 24 Mar 2017 19:04:57 +0000 (+0000) Subject: AMDGPU: Fold rcp/rsq of undef to undef X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f9d04c6fdc59561b367a523b485bde8c77bd46f3;p=llvm AMDGPU: Fold rcp/rsq of undef to undef git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298725 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index c259e7e9a93..845cf109897 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -3065,9 +3065,14 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { break; } - case Intrinsic::amdgcn_rcp: { - if (const ConstantFP *C = dyn_cast(II->getArgOperand(0))) { + Value *Src = II->getArgOperand(0); + + // TODO: Move to ConstantFolding/InstSimplify? + if (isa(Src)) + return replaceInstUsesWith(CI, Src); + + if (const ConstantFP *C = dyn_cast(Src)) { const APFloat &ArgVal = C->getValueAPF(); APFloat Val(ArgVal.getSemantics(), 1.0); APFloat::opStatus Status = Val.divide(ArgVal, @@ -3080,6 +3085,14 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { break; } + case Intrinsic::amdgcn_rsq: { + Value *Src = II->getArgOperand(0); + + // TODO: Move to ConstantFolding/InstSimplify? + if (isa(Src)) + return replaceInstUsesWith(CI, Src); + break; + } case Intrinsic::amdgcn_frexp_mant: case Intrinsic::amdgcn_frexp_exp: { Value *Src = II->getArgOperand(0); diff --git a/test/Transforms/InstCombine/amdgcn-intrinsics.ll b/test/Transforms/InstCombine/amdgcn-intrinsics.ll index 1afc22d97ac..deae5502bcd 100644 --- a/test/Transforms/InstCombine/amdgcn-intrinsics.ll +++ b/test/Transforms/InstCombine/amdgcn-intrinsics.ll @@ -7,6 +7,12 @@ 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_undef +; CHECK-NEXT: ret float undef +define float @test_constant_fold_rcp_f32_undef() nounwind { + %val = call float @llvm.amdgcn.rcp.f32(float undef) nounwind readnone + ret float %val +} ; CHECK-LABEL: @test_constant_fold_rcp_f32_1 ; CHECK-NEXT: ret float 1.000000e+00 @@ -50,6 +56,18 @@ define double @test_constant_fold_rcp_f64_43() nounwind { ret double %val } +; -------------------------------------------------------------------- +; llvm.amdgcn.rsq +; -------------------------------------------------------------------- + +declare float @llvm.amdgcn.rsq.f32(float) nounwind readnone + +; CHECK-LABEL: @test_constant_fold_rsq_f32_undef +; CHECK-NEXT: ret float undef +define float @test_constant_fold_rsq_f32_undef() nounwind { + %val = call float @llvm.amdgcn.rsq.f32(float undef) nounwind readnone + ret float %val +} ; -------------------------------------------------------------------- ; llvm.amdgcn.frexp.mant