From 2d8a36ee711989c911659e4697a4910f7396ed44 Mon Sep 17 00:00:00 2001 From: Michael Kuperstein Date: Thu, 5 Mar 2015 08:38:57 +0000 Subject: [PATCH] [InstCombine] Fix an assertion when fmul has a ConstantExpr operand isNormalFp and isFiniteNonZeroFp should not assume vector operands can not be constant expressions. Patch by Pawel Jurek Differential Revision: http://reviews.llvm.org/D8053 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231359 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 4 ++-- test/Transforms/InstCombine/fast-math.ll | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index c48e3c9f9ac..40aa7c5f454 100644 --- a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -422,7 +422,7 @@ static bool isFiniteNonZeroFp(Constant *C) { if (C->getType()->isVectorTy()) { for (unsigned I = 0, E = C->getType()->getVectorNumElements(); I != E; ++I) { - ConstantFP *CFP = dyn_cast(C->getAggregateElement(I)); + ConstantFP *CFP = dyn_cast_or_null(C->getAggregateElement(I)); if (!CFP || !CFP->getValueAPF().isFiniteNonZero()) return false; } @@ -437,7 +437,7 @@ static bool isNormalFp(Constant *C) { if (C->getType()->isVectorTy()) { for (unsigned I = 0, E = C->getType()->getVectorNumElements(); I != E; ++I) { - ConstantFP *CFP = dyn_cast(C->getAggregateElement(I)); + ConstantFP *CFP = dyn_cast_or_null(C->getAggregateElement(I)); if (!CFP || !CFP->getValueAPF().isNormal()) return false; } diff --git a/test/Transforms/InstCombine/fast-math.ll b/test/Transforms/InstCombine/fast-math.ll index c6081c39925..4eebdbdfacf 100644 --- a/test/Transforms/InstCombine/fast-math.ll +++ b/test/Transforms/InstCombine/fast-math.ll @@ -267,6 +267,14 @@ define <4 x float> @fmul3_vec(<4 x float> %f1, <4 x float> %f2) { ; CHECK: fmul fast <4 x float> %f1, } +; Make sure fmul with constant expression doesn't assert. +define <4 x float> @fmul3_vec_constexpr(<4 x float> %f1, <4 x float> %f2) { + %constExprMul = bitcast i128 trunc (i160 bitcast (<5 x float> to i160) to i128) to <4 x float> + %t1 = fdiv <4 x float> %f1, + %t3 = fmul fast <4 x float> %t1, %constExprMul + ret <4 x float> %t3 +} + ; Rule "X/C1 * C2 => X * (C2/C1) is not applicable if C2/C1 is either a special ; value of a denormal. The 0x3810000000000000 here take value FLT_MIN ;