Skip to content

Commit a60deaa

Browse files
[ConstantHoisting] Don't attempt to hoist ConstantInt vectors. (#85416)
The pass uses the TTI hook getIntImmCostIntrin that only supports scalar integer types. Whilst hoisting expensive vector constant is likely worthwhile, this is new behaviour and so I've followed the path taken by the GEP variant of collectConstantCandidates and simply bail for vector types.
1 parent 295cdd5 commit a60deaa

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

llvm/lib/Transforms/Scalar/ConstantHoisting.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ SetVector<Instruction *> ConstantHoistingPass::findConstantInsertionPoint(
363363
void ConstantHoistingPass::collectConstantCandidates(
364364
ConstCandMapType &ConstCandMap, Instruction *Inst, unsigned Idx,
365365
ConstantInt *ConstInt) {
366+
if (ConstInt->getType()->isVectorTy())
367+
return;
368+
366369
InstructionCost Cost;
367370
// Ask the target about the cost of materializing the constant for the given
368371
// instruction and operand index.

llvm/test/Transforms/ConstantHoisting/AArch64/large-immediate.ll

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2-
; RUN: opt -mtriple=arm64-darwin-unknown -S -passes=consthoist < %s | FileCheck %s
2+
; RUN: opt -mtriple=arm64-darwin-unknown -S -passes=consthoist < %s | FileCheck %s --check-prefixes=CHECK,CV
3+
; RUN: opt -mtriple=arm64-darwin-unknown -S -passes=consthoist -use-constant-int-for-fixed-length-splat -use-constant-int-for-scalable-splat < %s | FileCheck %s --check-prefixes=CHECK,CI
34

45
define i128 @test1(i128 %a) {
56
; CHECK-LABEL: define i128 @test1(
@@ -122,13 +123,37 @@ define i64 @sdiv_minsize(i64 %a) minsize {
122123
}
123124

124125
define <2 x i64> @sdiv_v2i64(<2 x i64> %a) {
125-
; CHECK-LABEL: define <2 x i64> @sdiv_v2i64(
126-
; CHECK-SAME: <2 x i64> [[A:%.*]]) {
127-
; CHECK-NEXT: [[TMP1:%.*]] = sdiv <2 x i64> [[A]], <i64 4294967087, i64 4294967087>
128-
; CHECK-NEXT: [[TMP2:%.*]] = add <2 x i64> [[TMP1]], <i64 4294967087, i64 4294967087>
129-
; CHECK-NEXT: ret <2 x i64> [[TMP2]]
126+
; CV-LABEL: define <2 x i64> @sdiv_v2i64(
127+
; CV-SAME: <2 x i64> [[A:%.*]]) {
128+
; CV-NEXT: [[TMP1:%.*]] = sdiv <2 x i64> [[A]], <i64 4294967087, i64 4294967087>
129+
; CV-NEXT: [[TMP2:%.*]] = add <2 x i64> [[TMP1]], <i64 4294967087, i64 4294967087>
130+
; CV-NEXT: ret <2 x i64> [[TMP2]]
131+
;
132+
; CI-LABEL: define <2 x i64> @sdiv_v2i64(
133+
; CI-SAME: <2 x i64> [[A:%.*]]) {
134+
; CI-NEXT: [[TMP1:%.*]] = sdiv <2 x i64> [[A]], splat (i64 4294967087)
135+
; CI-NEXT: [[TMP2:%.*]] = add <2 x i64> [[TMP1]], splat (i64 4294967087)
136+
; CI-NEXT: ret <2 x i64> [[TMP2]]
130137
;
131138
%1 = sdiv <2 x i64> %a, <i64 4294967087, i64 4294967087>
132139
%2 = add <2 x i64> %1, <i64 4294967087, i64 4294967087>
133140
ret <2 x i64> %2
134141
}
142+
143+
define <vscale x 2 x i64> @sdiv_nxv2i64(<vscale x 2 x i64> %a) {
144+
; CV-LABEL: define <vscale x 2 x i64> @sdiv_nxv2i64(
145+
; CV-SAME: <vscale x 2 x i64> [[A:%.*]]) {
146+
; CV-NEXT: [[TMP1:%.*]] = sdiv <vscale x 2 x i64> [[A]], shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 4294967087, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer)
147+
; CV-NEXT: [[TMP2:%.*]] = add <vscale x 2 x i64> [[TMP1]], shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 4294967087, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer)
148+
; CV-NEXT: ret <vscale x 2 x i64> [[TMP2]]
149+
;
150+
; CI-LABEL: define <vscale x 2 x i64> @sdiv_nxv2i64(
151+
; CI-SAME: <vscale x 2 x i64> [[A:%.*]]) {
152+
; CI-NEXT: [[TMP1:%.*]] = sdiv <vscale x 2 x i64> [[A]], splat (i64 4294967087)
153+
; CI-NEXT: [[TMP2:%.*]] = add <vscale x 2 x i64> [[TMP1]], splat (i64 4294967087)
154+
; CI-NEXT: ret <vscale x 2 x i64> [[TMP2]]
155+
;
156+
%1 = sdiv <vscale x 2 x i64> %a, splat (i64 4294967087)
157+
%2 = add <vscale x 2 x i64> %1, splat (i64 4294967087)
158+
ret <vscale x 2 x i64> %2
159+
}

0 commit comments

Comments
 (0)