Skip to content

Commit 801857c

Browse files
committed
[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
1 parent a625868 commit 801857c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

llvm/lib/IR/ConstantFold.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ static Constant *BitCastConstantVector(Constant *CV, VectorType *DstTy) {
4747
if (CV->isAllOnesValue()) return Constant::getAllOnesValue(DstTy);
4848
if (CV->isNullValue()) return Constant::getNullValue(DstTy);
4949

50+
// Do not iterate on scalable vector. The num of elements is unknown at
51+
// compile-time.
52+
if (DstTy->isScalable())
53+
return nullptr;
54+
5055
// If this cast changes element count then we can't handle it here:
5156
// doing so requires endianness information. This should be handled by
5257
// Analysis/ConstantFolding.cpp
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -constprop -S -verify | FileCheck %s
3+
4+
define <vscale x 4 x float> @bitcast_scalable_constant() {
5+
; CHECK-LABEL: @bitcast_scalable_constant(
6+
; 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>)
7+
;
8+
%i1 = insertelement <vscale x 4 x i32> undef, i32 1, i32 0
9+
%i2 = shufflevector <vscale x 4 x i32> %i1, <vscale x 4 x i32> undef, <vscale x 4 x i32> zeroinitializer
10+
%i3 = bitcast <vscale x 4 x i32> %i2 to <vscale x 4 x float>
11+
ret <vscale x 4 x float> %i3
12+
}

0 commit comments

Comments
 (0)