From 4c93a0f09225b428fb0f28f1c540f5ff5dd5bb3c Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Fri, 21 Jan 2011 01:12:09 +0000 Subject: [PATCH] Add a constant folding of casts from zero to zero. Fixes PR9011! While here, I'd like to complain about how vector is not an aggregate type according to llvm::Type::isAggregateType(), but they're listed under aggregate types in the LangRef and zero vectors are stored as ConstantAggregateZero. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123956 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/ConstantFold.cpp | 4 +++ test/Transforms/ConstProp/constant-expr.ll | 35 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index a21b4a28e47..3fea1910ffe 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -511,10 +511,14 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V, return Constant::getNullValue(DestTy); return UndefValue::get(DestTy); } + // No compile-time operations on this type yet. if (V->getType()->isPPC_FP128Ty() || DestTy->isPPC_FP128Ty()) return 0; + if (V->isNullValue() && !DestTy->isX86_MMXTy()) + return Constant::getNullValue(DestTy); + // If the cast operand is a constant expression, there's a few things we can // do to try to simplify it. if (ConstantExpr *CE = dyn_cast(V)) { diff --git a/test/Transforms/ConstProp/constant-expr.ll b/test/Transforms/ConstProp/constant-expr.ll index 556ed1f652a..33ed1a53c3e 100644 --- a/test/Transforms/ConstProp/constant-expr.ll +++ b/test/Transforms/ConstProp/constant-expr.ll @@ -65,3 +65,38 @@ ; No check line. This used to crash llvm-as. @T6 = global <2 x i1> fcmp ole (<2 x float> fdiv (<2 x float> undef, <2 x float> ), <2 x float> zeroinitializer) + + +; PR9011 + +@pr9011_1 = constant <4 x i32> zext (<4 x i8> zeroinitializer to <4 x i32>) +; CHECK: pr9011_1 = constant <4 x i32> zeroinitializer +@pr9011_2 = constant <4 x i32> sext (<4 x i8> zeroinitializer to <4 x i32>) +; CHECK: pr9011_2 = constant <4 x i32> zeroinitializer +@pr9011_3 = constant <4 x i32> bitcast (<16 x i8> zeroinitializer to <4 x i32>) +; CHECK: pr9011_3 = constant <4 x i32> zeroinitializer +@pr9011_4 = constant <4 x float> uitofp (<4 x i8> zeroinitializer to <4 x float>) +; CHECK: pr9011_4 = constant <4 x float> zeroinitializer +@pr9011_5 = constant <4 x float> sitofp (<4 x i8> zeroinitializer to <4 x float>) +; CHECK: pr9011_5 = constant <4 x float> zeroinitializer +@pr9011_6 = constant <4 x i32> fptosi (<4 x float> zeroinitializer to <4 x i32>) +; CHECK: pr9011_6 = constant <4 x i32> zeroinitializer +@pr9011_7 = constant <4 x i32> fptoui (<4 x float> zeroinitializer to <4 x i32>) +; CHECK: pr9011_7 = constant <4 x i32> zeroinitializer +@pr9011_8 = constant <4 x float> fptrunc (<4 x double> zeroinitializer to <4 x float>) +; CHECK: pr9011_8 = constant <4 x float> zeroinitializer +@pr9011_9 = constant <4 x double> fpext (<4 x float> zeroinitializer to <4 x double>) +; CHECK: pr9011_9 = constant <4 x double> zeroinitializer + +@pr9011_10 = constant <4 x double> bitcast (i256 0 to <4 x double>) +; CHECK: pr9011_10 = constant <4 x double> zeroinitializer +@pr9011_11 = constant <4 x float> bitcast (i128 0 to <4 x float>) +; CHECK: pr9011_11 = constant <4 x float> zeroinitializer +@pr9011_12 = constant <4 x i32> bitcast (i128 0 to <4 x i32>) +; CHECK: pr9011_12 = constant <4 x i32> zeroinitializer +@pr9011_13 = constant i256 bitcast (<4 x double> zeroinitializer to i256) +; CHECK: pr9011_13 = constant i256 0 +@pr9011_14 = constant i128 bitcast (<4 x float> zeroinitializer to i128) +; CHECK: pr9011_14 = constant i128 0 +@pr9011_15 = constant i128 bitcast (<4 x i32> zeroinitializer to i128) +; CHECK: pr9011_15 = constant i128 0 -- 2.34.1