Skip to content

[LLVM][CodeGen] Lower ConstantInt vectors like shufflevector base splats. #144395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1791,8 +1791,26 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value *V) {
if (const Constant *C = dyn_cast<Constant>(V)) {
EVT VT = TLI.getValueType(DAG.getDataLayout(), V->getType(), true);

if (const ConstantInt *CI = dyn_cast<ConstantInt>(C))
return DAG.getConstant(*CI, getCurSDLoc(), VT);
if (const ConstantInt *CI = dyn_cast<ConstantInt>(C)) {
SDLoc DL = getCurSDLoc();

// DAG.getConstant() may attempt to legalise the vector constant which can
// significantly change the combines applied to the DAG. To reduce the
// divergence when enabling ConstantInt based vectors we try to construct
// the DAG in the same way as shufflevector based splats. TODO: The
// divergence sometimes leads to better optimisations. Ideally we should
// prevent DAG.getConstant() from legalising too early but there are some
// degradations preventing this.
if (VT.isScalableVector())
return DAG.getNode(
ISD::SPLAT_VECTOR, DL, VT,
DAG.getConstant(CI->getValue(), DL, VT.getVectorElementType()));
if (VT.isFixedLengthVector())
return DAG.getSplatBuildVector(
VT, DL,
DAG.getConstant(CI->getValue(), DL, VT.getVectorElementType()));
return DAG.getConstant(*CI, DL, VT);
}

if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
return DAG.getGlobalAddress(GV, getCurSDLoc(), VT);
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/AArch64/sve-expand-div.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=aarch64-linux-gnu < %s | FileCheck %s
; RUN: llc -mtriple=aarch64-linux-gnu -use-constant-int-for-scalable-splat < %s | FileCheck %s

; Check that expensive divides are expanded into a more performant sequence

Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/AArch64/sve-fixed-length-sdiv-pow2.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
; RUN: llc -aarch64-sve-vector-bits-min=256 < %s | FileCheck %s -check-prefixes=CHECK,VBITS_GE_256
; RUN: llc -aarch64-sve-vector-bits-min=512 < %s | FileCheck %s -check-prefixes=CHECK,VBITS_GE_512
; RUN: llc -aarch64-sve-vector-bits-min=2048 < %s | FileCheck %s -check-prefixes=CHECK,VBITS_GE_512
; RUN: llc -aarch64-sve-vector-bits-min=128 -use-constant-int-for-fixed-length-splat < %s | FileCheck %s -check-prefixes=CHECK,VBITS_GE_128

target triple = "aarch64-unknown-linux-gnu"

Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/AArch64/sve-sdiv-pow2.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s | FileCheck %s
; RUN: llc -use-constant-int-for-scalable-splat < %s | FileCheck %s

target triple = "aarch64-unknown-linux-gnu"

Expand Down
Loading