diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -5595,11 +5595,10 @@ Value *llvm::SimplifyInstruction(Instruction *I, const SimplifyQuery &SQ, OptimizationRemarkEmitter *ORE) { const SimplifyQuery Q = SQ.CxtI ? SQ : SQ.getWithInstruction(I); - Value *Result; + Value *Result = nullptr; switch (I->getOpcode()) { default: - Result = ConstantFoldInstruction(I, Q.DL, Q.TLI); break; case Instruction::FNeg: Result = SimplifyFNegInst(I->getOperand(0), I->getFastMathFlags(), Q); @@ -5741,11 +5740,9 @@ Result = SimplifyCastInst(I->getOpcode(), I->getOperand(0), I->getType(), Q); break; - case Instruction::Alloca: - // No simplifications for Alloca and it can't be constant folded. - Result = nullptr; - break; } + if (!Result) + Result = ConstantFoldInstruction(I, Q.DL, Q.TLI); /// If called on unreachable code, the above logic may report that the /// instruction simplified to itself. Make life easier for users by diff --git a/llvm/test/Analysis/ConstantFolding/vscale-shufflevector.ll b/llvm/test/Analysis/ConstantFolding/vscale-shufflevector.ll --- a/llvm/test/Analysis/ConstantFolding/vscale-shufflevector.ll +++ b/llvm/test/Analysis/ConstantFolding/vscale-shufflevector.ll @@ -15,9 +15,7 @@ ; the compiler. It happens to be the case that this will be the result. ; CHECK-LABEL: define @vscale_version() -; CHECK-NEXT: %splatter = insertelement undef, i1 true, i32 0 -; CHECK-NEXT: %foo = shufflevector %splatter, undef, zeroinitializer -; CHECK-NEXT: ret %foo +; CHECK-NEXT: ret shufflevector ( insertelement ( undef, i1 true, i32 0), undef, zeroinitializer) define @vscale_version() { %splatter = insertelement undef, i1 true, i32 0 diff --git a/llvm/test/Transforms/InstSimplify/select.ll b/llvm/test/Transforms/InstSimplify/select.ll --- a/llvm/test/Transforms/InstSimplify/select.ll +++ b/llvm/test/Transforms/InstSimplify/select.ll @@ -890,8 +890,7 @@ ; Negative tests. Don't fold if the non-undef operand is a constexpr. define i32 @all_constant_false_undef_true_constexpr() { ; CHECK-LABEL: @all_constant_false_undef_true_constexpr( -; CHECK-NEXT: [[S:%.*]] = select i1 ptrtoint (i32 ()* @all_constant_false_undef_true_constexpr to i1), i32 ptrtoint (i32 ()* @all_constant_false_undef_true_constexpr to i32), i32 undef -; CHECK-NEXT: ret i32 [[S]] +; CHECK-NEXT: ret i32 select (i1 ptrtoint (i32 ()* @all_constant_false_undef_true_constexpr to i1), i32 ptrtoint (i32 ()* @all_constant_false_undef_true_constexpr to i32), i32 undef) ; %s = select i1 ptrtoint (i32 ()* @all_constant_false_undef_true_constexpr to i1), i32 ptrtoint (i32 ()* @all_constant_false_undef_true_constexpr to i32), i32 undef ret i32 %s @@ -899,8 +898,7 @@ define i32 @all_constant_true_undef_false_constexpr() { ; CHECK-LABEL: @all_constant_true_undef_false_constexpr( -; CHECK-NEXT: [[S:%.*]] = select i1 ptrtoint (i32 ()* @all_constant_true_undef_false_constexpr to i1), i32 undef, i32 ptrtoint (i32 ()* @all_constant_true_undef_false_constexpr to i32) -; CHECK-NEXT: ret i32 [[S]] +; CHECK-NEXT: ret i32 select (i1 ptrtoint (i32 ()* @all_constant_true_undef_false_constexpr to i1), i32 undef, i32 ptrtoint (i32 ()* @all_constant_true_undef_false_constexpr to i32)) ; %s = select i1 ptrtoint (i32 ()* @all_constant_true_undef_false_constexpr to i1), i32 undef, i32 ptrtoint (i32 ()* @all_constant_true_undef_false_constexpr to i32) ret i32 %s @@ -909,8 +907,7 @@ ; Negative tests. Don't fold if the non-undef operand is a vector containing a constexpr. define <2 x i32> @all_constant_false_undef_true_constexpr_vec() { ; CHECK-LABEL: @all_constant_false_undef_true_constexpr_vec( -; CHECK-NEXT: [[S:%.*]] = select i1 ptrtoint (<2 x i32> ()* @all_constant_false_undef_true_constexpr_vec to i1), <2 x i32> ()* @all_constant_false_undef_true_constexpr_vec to i32), i32 -1>, <2 x i32> undef -; CHECK-NEXT: ret <2 x i32> [[S]] +; CHECK-NEXT: ret <2 x i32> select (i1 ptrtoint (<2 x i32> ()* @all_constant_false_undef_true_constexpr_vec to i1), <2 x i32> ()* @all_constant_false_undef_true_constexpr_vec to i32), i32 -1>, <2 x i32> undef) ; %s = select i1 ptrtoint (<2 x i32> ()* @all_constant_false_undef_true_constexpr_vec to i1), <2 x i32> ()* @all_constant_false_undef_true_constexpr_vec to i32), i32 -1>, <2 x i32> undef ret <2 x i32> %s @@ -918,8 +915,7 @@ define <2 x i32> @all_constant_true_undef_false_constexpr_vec() { ; CHECK-LABEL: @all_constant_true_undef_false_constexpr_vec( -; CHECK-NEXT: [[S:%.*]] = select i1 ptrtoint (<2 x i32> ()* @all_constant_true_undef_false_constexpr_vec to i1), <2 x i32> undef, <2 x i32> ()* @all_constant_true_undef_false_constexpr_vec to i32)> -; CHECK-NEXT: ret <2 x i32> [[S]] +; CHECK-NEXT: ret <2 x i32> select (i1 ptrtoint (<2 x i32> ()* @all_constant_true_undef_false_constexpr_vec to i1), <2 x i32> undef, <2 x i32> ()* @all_constant_true_undef_false_constexpr_vec to i32)>) ; %s = select i1 ptrtoint (<2 x i32> ()* @all_constant_true_undef_false_constexpr_vec to i1), <2 x i32> undef, <2 x i32> ()* @all_constant_true_undef_false_constexpr_vec to i32)> ret <2 x i32> %s