[llvm] 801857c - [ConstantFold][SVE] Fix constant folding for bitcast.
Huihui Zhang via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 5 15:41:31 PST 2020
Author: Huihui Zhang
Date: 2020-02-05T15:39:57-08:00
New Revision: 801857c59ea647442b1302139169ec37f81d8cce
URL: https://github.com/llvm/llvm-project/commit/801857c59ea647442b1302139169ec37f81d8cce
DIFF: https://github.com/llvm/llvm-project/commit/801857c59ea647442b1302139169ec37f81d8cce.diff
LOG: [ConstantFold][SVE] Fix constant folding for bitcast.
Do not iterate on scalable vector type in BitCastConstantVector.
Continuation work of D70985, D71147.
Support for folding bitcast into splat value is kept in D74095, as
it depends on D71637.
Differential Revision: https://reviews.llvm.org/D71389
Added:
llvm/test/Analysis/ConstantFolding/bitcast.ll
Modified:
llvm/lib/IR/ConstantFold.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index cd037f0b2225..ef679fbb5ab5 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/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/llvm/test/Analysis/ConstantFolding/bitcast.ll b/llvm/test/Analysis/ConstantFolding/bitcast.ll
new file mode 100644
index 000000000000..68e4a5fe374d
--- /dev/null
+++ b/llvm/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 <vscale x 4 x float> @bitcast_scalable_constant() {
+; CHECK-LABEL: @bitcast_scalable_constant(
+; CHECK-NEXT: ret <vscale x 4 x float> bitcast (<vscale x 4 x i32> shufflevector (<vscale x 4 x i32> insertelement (<vscale x 4 x i32> undef, i32 1, i32 0), <vscale x 4 x i32> undef, <vscale x 4 x i32> zeroinitializer) to <vscale x 4 x float>)
+;
+ %i1 = insertelement <vscale x 4 x i32> undef, i32 1, i32 0
+ %i2 = shufflevector <vscale x 4 x i32> %i1, <vscale x 4 x i32> undef, <vscale x 4 x i32> zeroinitializer
+ %i3 = bitcast <vscale x 4 x i32> %i2 to <vscale x 4 x float>
+ ret <vscale x 4 x float> %i3
+}
More information about the llvm-commits
mailing list