diff --git a/lib/IR/ConstantFold.cpp b/lib/IR/ConstantFold.cpp index cd037f0b222..ef679fbb5ab 100644 --- a/lib/IR/ConstantFold.cpp +++ b/lib/IR/ConstantFold.cpp @@ -47,6 +47,11 @@ static Constant *BitCastConstantVector(Constant *CV, VectorType *DstTy) { if (CV->isAllOnesValue()) return Constant::getAllOnesValue(DstTy); if (CV->isNullValue()) return Constant::getNullValue(DstTy); + // Do not iterate on scalable vector. The num of elements is unknown at + // compile-time. + if (DstTy->isScalable()) + return nullptr; + // If this cast changes element count then we can't handle it here: // doing so requires endianness information. This should be handled by // Analysis/ConstantFolding.cpp diff --git a/test/Analysis/ConstantFolding/bitcast.ll b/test/Analysis/ConstantFolding/bitcast.ll new file mode 100644 index 00000000000..68e4a5fe374 --- /dev/null +++ b/test/Analysis/ConstantFolding/bitcast.ll @@ -0,0 +1,12 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -constprop -S -verify | FileCheck %s + +define @bitcast_scalable_constant() { +; CHECK-LABEL: @bitcast_scalable_constant( +; CHECK-NEXT: ret bitcast ( shufflevector ( insertelement ( undef, i32 1, i32 0), undef, zeroinitializer) to ) +; + %i1 = insertelement undef, i32 1, i32 0 + %i2 = shufflevector %i1, undef, zeroinitializer + %i3 = bitcast %i2 to + ret %i3 +}