Skip to content

Commit

Permalink
[SVE] Take constant fold fast path for splatted vscale vectors
Browse files Browse the repository at this point in the history
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
  • Loading branch information
christetreault-llvm committed Nov 17, 2020
1 parent 44a11c3 commit 792f8e1
Show file tree
Hide file tree
Showing 3 changed files with 844 additions and 7 deletions.
10 changes: 5 additions & 5 deletions llvm/lib/IR/ConstantFold.cpp
Expand Up @@ -2042,18 +2042,18 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
}
} else if (auto *C1VTy = dyn_cast<VectorType>(C1->getType())) {

// Do not iterate on scalable vector. The number of elements is unknown at
// compile-time.
if (isa<ScalableVectorType>(C1VTy))
return nullptr;

// Fast path for splatted constants.
if (Constant *C1Splat = C1->getSplatValue())
if (Constant *C2Splat = C2->getSplatValue())
return ConstantVector::getSplat(
C1VTy->getElementCount(),
ConstantExpr::getCompare(pred, C1Splat, C2Splat));

// Do not iterate on scalable vector. The number of elements is unknown at
// compile-time.
if (isa<ScalableVectorType>(C1VTy))
return nullptr;

// If we can constant fold the comparison of each element, constant fold
// the whole vector comparison.
SmallVector<Constant*, 4> ResElts;
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Transforms/InstSimplify/ConstProp/vscale.ll
Expand Up @@ -208,7 +208,7 @@ define <vscale x 4 x i32> @shufflevector() {

define <vscale x 2 x double> @load() {
; CHECK-LABEL: @load(
; 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)
; 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
; CHECK-NEXT: ret <vscale x 2 x double> [[R]]
;
%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)
Expand Down Expand Up @@ -262,7 +262,7 @@ define <vscale x 4 x i1> @icmp_undef() {

define <vscale x 4 x i1> @icmp_zero() {
; CHECK-LABEL: @icmp_zero(
; CHECK-NEXT: ret <vscale x 4 x i1> icmp eq (<vscale x 4 x i32> zeroinitializer, <vscale x 4 x i32> zeroinitializer)
; 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)
;
%r = icmp eq <vscale x 4 x i32> zeroinitializer, zeroinitializer
ret <vscale x 4 x i1> %r
Expand Down

0 comments on commit 792f8e1

Please sign in to comment.