diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1659,7 +1659,6 @@ // Determine if this is a vector of ConstantFPs and if so, return the minimal // type we can safely truncate all elements to. -// TODO: Make these support undef elements. static Type *shrinkFPConstantVector(Value *V) { auto *CV = dyn_cast(V); auto *CVVTy = dyn_cast(V->getType()); @@ -1673,6 +1672,9 @@ // For fixed-width vectors we find the minimal type by looking // through the constant values of the vector. for (unsigned i = 0; i != NumElts; ++i) { + if (isa(CV->getAggregateElement(i))) + continue; + auto *CFP = dyn_cast_or_null(CV->getAggregateElement(i)); if (!CFP) return nullptr; @@ -1688,7 +1690,7 @@ } // Make a vector type from the minimal type. - return FixedVectorType::get(MinType, NumElts); + return MinType ? FixedVectorType::get(MinType, NumElts) : nullptr; } /// Find the minimum FP type we can safely truncate to. diff --git a/llvm/test/Transforms/InstCombine/fpextend.ll b/llvm/test/Transforms/InstCombine/fpextend.ll --- a/llvm/test/Transforms/InstCombine/fpextend.ll +++ b/llvm/test/Transforms/InstCombine/fpextend.ll @@ -83,12 +83,9 @@ } ; Test with an undef element -; TODO: Support undef elements. define <2 x float> @test6_undef(<2 x float> %x) nounwind { ; CHECK-LABEL: @test6_undef( -; CHECK-NEXT: [[T1:%.*]] = fpext <2 x float> [[X:%.*]] to <2 x double> -; CHECK-NEXT: [[T3:%.*]] = fadd <2 x double> [[T1]], -; CHECK-NEXT: [[T34:%.*]] = fptrunc <2 x double> [[T3]] to <2 x float> +; CHECK-NEXT: [[T34:%.*]] = fadd <2 x float> [[X:%.*]], ; CHECK-NEXT: ret <2 x float> [[T34]] ; %t1 = fpext <2 x float> %x to <2 x double>