From 0be7155350be3f26108487f0cb10ae0b183ea5a8 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Thu, 28 Jul 2016 02:29:06 +0000 Subject: [PATCH] [InstCombine] Handle failures from ConstantFoldConstantExpression ConstantFoldConstantExpression returns null when folding fails. This fixes PR28745. llvm-svn: 276952 --- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 3 ++- llvm/test/Transforms/InstCombine/cast.ll | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 0d79733aae93..d41c449c7d20 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -162,7 +162,8 @@ Value *InstCombiner::EvaluateInDifferentType(Value *V, Type *Ty, C = ConstantExpr::getIntegerCast(C, Ty, isSigned /*Sext or ZExt*/); // If we got a constantexpr back, try to simplify it with DL info. if (ConstantExpr *CE = dyn_cast(C)) - C = ConstantFoldConstantExpression(CE, DL, TLI); + if (Constant *FoldedC = ConstantFoldConstantExpression(CE, DL, TLI)) + C = FoldedC; return C; } diff --git a/llvm/test/Transforms/InstCombine/cast.ll b/llvm/test/Transforms/InstCombine/cast.ll index 715956fafeb3..e4509112eebf 100644 --- a/llvm/test/Transforms/InstCombine/cast.ll +++ b/llvm/test/Transforms/InstCombine/cast.ll @@ -1372,3 +1372,11 @@ define i16 @PR24763(i8 %V) { %t = trunc i32 %l to i16 ret i16 %t } + +define i64 @PR28745() { +; CHECK-LABEL: @PR28745( +; CHECK-NEXT: ret i64 zext (i32 extractvalue ({ i32 } select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32> to <2 x i16>), i32 0), i16 0), { i32 } { i32 1 }, { i32 } zeroinitializer), 0) to i64) + + %b = zext i32 extractvalue ({ i32 } select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32> to <2 x i16>), i32 0), i16 0), { i32 } { i32 1 }, { i32 } zeroinitializer), 0) to i64 + ret i64 %b +}