Skip to content

Commit 792f8e1

Browse files
[SVE] Take constant fold fast path for splatted vscale vectors
This should be a perfectly reasonable operation for scalable vectors. Currently, it only works for zeroinitializer values of ScalableVectorType, but the fundamental operation is sound and it should be possible to make it work for other splats Reviewed By: david-arm Differential Revision: https://reviews.llvm.org/D77442
1 parent 44a11c3 commit 792f8e1

File tree

3 files changed

+844
-7
lines changed

3 files changed

+844
-7
lines changed

llvm/lib/IR/ConstantFold.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,18 +2042,18 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
20422042
}
20432043
} else if (auto *C1VTy = dyn_cast<VectorType>(C1->getType())) {
20442044

2045-
// Do not iterate on scalable vector. The number of elements is unknown at
2046-
// compile-time.
2047-
if (isa<ScalableVectorType>(C1VTy))
2048-
return nullptr;
2049-
20502045
// Fast path for splatted constants.
20512046
if (Constant *C1Splat = C1->getSplatValue())
20522047
if (Constant *C2Splat = C2->getSplatValue())
20532048
return ConstantVector::getSplat(
20542049
C1VTy->getElementCount(),
20552050
ConstantExpr::getCompare(pred, C1Splat, C2Splat));
20562051

2052+
// Do not iterate on scalable vector. The number of elements is unknown at
2053+
// compile-time.
2054+
if (isa<ScalableVectorType>(C1VTy))
2055+
return nullptr;
2056+
20572057
// If we can constant fold the comparison of each element, constant fold
20582058
// the whole vector comparison.
20592059
SmallVector<Constant*, 4> ResElts;

llvm/test/Transforms/InstSimplify/ConstProp/vscale.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ define <vscale x 4 x i32> @shufflevector() {
208208

209209
define <vscale x 2 x double> @load() {
210210
; CHECK-LABEL: @load(
211-
; CHECK-NEXT: [[R:%.*]] = load <vscale x 2 x double>, <vscale x 2 x double>* getelementptr (<vscale x 2 x double>, <vscale x 2 x double>* null, i64 1)
211+
; CHECK-NEXT: [[R:%.*]] = load <vscale x 2 x double>, <vscale x 2 x double>* getelementptr (<vscale x 2 x double>, <vscale x 2 x double>* null, i64 1), align 16
212212
; CHECK-NEXT: ret <vscale x 2 x double> [[R]]
213213
;
214214
%r = load <vscale x 2 x double>, <vscale x 2 x double>* getelementptr (<vscale x 2 x double>, <vscale x 2 x double>* null, i64 1)
@@ -262,7 +262,7 @@ define <vscale x 4 x i1> @icmp_undef() {
262262

263263
define <vscale x 4 x i1> @icmp_zero() {
264264
; CHECK-LABEL: @icmp_zero(
265-
; CHECK-NEXT: ret <vscale x 4 x i1> icmp eq (<vscale x 4 x i32> zeroinitializer, <vscale x 4 x i32> zeroinitializer)
265+
; CHECK-NEXT: ret <vscale x 4 x i1> shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> undef, i1 true, i32 0), <vscale x 4 x i1> undef, <vscale x 4 x i32> zeroinitializer)
266266
;
267267
%r = icmp eq <vscale x 4 x i32> zeroinitializer, zeroinitializer
268268
ret <vscale x 4 x i1> %r

0 commit comments

Comments
 (0)