From aae294a712a4f578b22871ac1025a8defa9c4f63 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Sat, 17 Jun 2017 00:07:22 +0000 Subject: [PATCH] [InstCombine] Make FPMathOperator working with ConstantExpression(s). Fixes PR33453. Differential Revision: https://reviews.llvm.org/D34303 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305618 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Operator.h | 9 ++++++++- test/Transforms/InstCombine/pr33453.ll | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/Transforms/InstCombine/pr33453.ll diff --git a/include/llvm/IR/Operator.h b/include/llvm/IR/Operator.h index 6eb5998478c65..c7f4697e93e74 100644 --- a/include/llvm/IR/Operator.h +++ b/include/llvm/IR/Operator.h @@ -328,8 +328,15 @@ class FPMathOperator : public Operator { return I->getType()->isFPOrFPVectorTy() || I->getOpcode() == Instruction::FCmp; } + + static inline bool classof(const ConstantExpr *CE) { + return CE->getType()->isFPOrFPVectorTy() || + CE->getOpcode() == Instruction::FCmp; + } + static inline bool classof(const Value *V) { - return isa(V) && classof(cast(V)); + return (isa(V) && classof(cast(V))) || + (isa(V) && classof(cast(V))); } }; diff --git a/test/Transforms/InstCombine/pr33453.ll b/test/Transforms/InstCombine/pr33453.ll new file mode 100644 index 0000000000000..dee4c5bf566be --- /dev/null +++ b/test/Transforms/InstCombine/pr33453.ll @@ -0,0 +1,15 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -instcombine -S %s | FileCheck %s + +@g1 = external global i16 +@g2 = external global i16 + +define float @patatino() { +; CHECK-LABEL: @patatino( +; CHECK-NEXT: ret float fmul (float uitofp (i1 icmp eq (i16* getelementptr inbounds (i16, i16* @g2, i64 1), i16* @g1) to float), float uitofp (i1 icmp eq (i16* getelementptr inbounds (i16, i16* @g2, i64 1), i16* @g1) to float)) +; + %call = call float @fabsf(float fmul (float uitofp (i1 icmp eq (i16* getelementptr inbounds (i16, i16* @g2, i64 1), i16* @g1) to float), float uitofp (i1 icmp eq (i16* getelementptr inbounds (i16, i16* @g2, i64 1), i16* @g1) to float))) + ret float %call +} + +declare float @fabsf(float)