[llvm] r265825 - Propagate Undef in llvm.cos Intrinsic
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 8 11:21:11 PDT 2016
Author: sanjoy
Date: Fri Apr 8 13:21:11 2016
New Revision: 265825
URL: http://llvm.org/viewvc/llvm-project?rev=265825&view=rev
Log:
Propagate Undef in llvm.cos Intrinsic
Summary:
The llvm cos intrinsic currently does not propagate undef's. This change
transforms cos(undef) to null value or 0.
There are 2 test cases added as well.
Patch by Anna Thomas!
Reviewers: sanjoy
Subscribers: majnemer, llvm-commits
Differential Revision: http://reviews.llvm.org/D18863
Added:
llvm/trunk/test/Transforms/InstCombine/cos-intrinsic.ll
Modified:
llvm/trunk/lib/Analysis/ConstantFolding.cpp
Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=265825&r1=265824&r2=265825&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Fri Apr 8 13:21:11 2016
@@ -1443,6 +1443,11 @@ Constant *ConstantFoldScalarCall(StringR
ArrayRef<Constant *> Operands,
const TargetLibraryInfo *TLI) {
if (Operands.size() == 1) {
+ if (isa<UndefValue>(Operands[0])) {
+ // cosine(arg) is between -1 and 1. cosine(invalid arg) is NaN
+ if (IntrinsicID == Intrinsic::cos)
+ return Constant::getNullValue(Ty);
+ }
if (ConstantFP *Op = dyn_cast<ConstantFP>(Operands[0])) {
if (IntrinsicID == Intrinsic::convert_to_fp16) {
APFloat Val(Op->getValueAPF());
Added: llvm/trunk/test/Transforms/InstCombine/cos-intrinsic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/cos-intrinsic.ll?rev=265825&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/cos-intrinsic.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/cos-intrinsic.ll Fri Apr 8 13:21:11 2016
@@ -0,0 +1,26 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; This test makes sure that the undef is propagated for the cos instrinsic
+
+declare double @llvm.cos.f64(double %Val)
+declare float @llvm.cos.f32(float %Val)
+
+; Function Attrs: nounwind readnone
+define double @test1() {
+; CHECK-LABEL: define double @test1(
+; CHECK-NEXT: ret double 0.000000e+00
+ %1 = call double @llvm.cos.f64(double undef)
+ ret double %1
+}
+
+
+; Function Attrs: nounwind readnone
+define float @test2(float %d) {
+; CHECK-LABEL: define float @test2(
+; CHECK-NEXT: %cosval = call float @llvm.cos.f32(float %d)
+ %cosval = call float @llvm.cos.f32(float %d)
+ %cosval2 = call float @llvm.cos.f32(float undef)
+ %fsum = fadd float %cosval2, %cosval
+ ret float %fsum
+; CHECK-NEXT: %fsum
+; CHECK: ret float %fsum
+}
More information about the llvm-commits
mailing list