Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/matcher_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
return is_alltrue ? BoolTest::eq : BoolTest::ne;
}

static bool vector_indexes_needs_massaging(BasicType ety, int vlen) {
static bool vector_indexes_needs_pruning(BasicType bt, int vlen) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/arm/matcher_arm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
return BoolTest::illegal;
}

static bool vector_indexes_needs_massaging(BasicType ety, int vlen) {
static bool vector_indexes_needs_pruning(BasicType bt, int vlen) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/ppc/matcher_ppc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
return BoolTest::illegal;
}

static bool vector_indexes_needs_massaging(BasicType ety, int vlen) {
static bool vector_indexes_needs_pruning(BasicType bt, int vlen) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/matcher_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
return is_alltrue ? BoolTest::eq : BoolTest::ne;
}

static bool vector_indexes_needs_massaging(BasicType ety, int vlen) {
static bool vector_indexes_needs_pruning(BasicType bt, int vlen) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/s390/matcher_s390.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
return BoolTest::illegal;
}

static bool vector_indexes_needs_massaging(BasicType ety, int vlen) {
static bool vector_indexes_needs_pruning(BasicType bt, int vlen) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6443,8 +6443,8 @@ void C2_MacroAssembler::vector_rearrange_int_float(BasicType bt, XMMRegister dst
}
}

void C2_MacroAssembler::select_from_two_vector_evex(BasicType elem_bt, XMMRegister dst, XMMRegister src1,
XMMRegister src2, int vlen_enc) {
void C2_MacroAssembler::select_from_two_vectors_evex(BasicType elem_bt, XMMRegister dst, XMMRegister src1,
XMMRegister src2, int vlen_enc) {
switch(elem_bt) {
case T_BYTE:
evpermi2b(dst, src1, src2, vlen_enc);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/x86/c2_MacroAssembler_x86.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,6 @@
void vgather8b_offset(BasicType elem_bt, XMMRegister dst, Register base, Register idx_base,
Register offset, Register rtmp, int vlen_enc);

void select_from_two_vector_evex(BasicType elem_bt, XMMRegister dst, XMMRegister src1, XMMRegister src2, int vlen_enc);
void select_from_two_vectors_evex(BasicType elem_bt, XMMRegister dst, XMMRegister src1, XMMRegister src2, int vlen_enc);

#endif // CPU_X86_C2_MACROASSEMBLER_X86_HPP
4 changes: 2 additions & 2 deletions src/hotspot/cpu/x86/matcher_x86.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@
return BoolTest::lt;
}

static bool vector_indexes_needs_massaging(BasicType ety, int vlen) {
switch(ety) {
static bool vector_indexes_needs_pruning(BasicType bt, int vlen) {
switch(bt) {
default:
return false;
case T_SHORT:
Expand Down
10 changes: 5 additions & 5 deletions src/hotspot/cpu/x86/x86.ad
Original file line number Diff line number Diff line change
Expand Up @@ -10487,15 +10487,15 @@ instruct DoubleClassCheck_reg_reg_vfpclass(rRegI dst, regD src, kReg ktmp, rFlag
%}


instruct selectFromTwoVec_evex(vec dst, vec src1, vec src2)
instruct vector_selectfrom_twovectors_reg_evex(vec index, vec src1, vec src2)
%{
match(Set dst (SelectFromTwoVector (Binary dst src1) src2));
effect(TEMP dst);
format %{ "select_from_two_vector $dst, $src1, $src2 \t!" %}
match(Set index (SelectFromTwoVector (Binary index src1) src2));
effect(TEMP index);
format %{ "select_from_two_vector $index, $src1, $src2 \t!" %}
ins_encode %{
int vlen_enc = vector_length_encoding(this);
BasicType bt = Matcher::vector_element_basic_type(this);
__ select_from_two_vector_evex(bt, $dst$$XMMRegister, $src1$$XMMRegister, $src2$$XMMRegister, vlen_enc);
__ select_from_two_vectors_evex(bt, $index$$XMMRegister, $src1$$XMMRegister, $src2$$XMMRegister, vlen_enc);
%}
ins_pipe(pipe_slow);
%}
96 changes: 46 additions & 50 deletions src/hotspot/share/opto/vectornode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2087,68 +2087,63 @@ Node* VectorBlendNode::Identity(PhaseGVN* phase) {
Node* SelectFromTwoVectorNode::Ideal(PhaseGVN* phase, bool can_reshape) {
int num_elem = vect_type()->length();
BasicType elem_bt = vect_type()->element_basic_type();
// Keep the node if it is supported, else lower it to other nodes.
if (Matcher::match_rule_supported_vector(Op_SelectFromTwoVector, num_elem, elem_bt)) {
return nullptr;
}
Node* index_vec = in(1);
Node* src1 = in(2);
Node* src2 = in(3);
Node* src1 = in(2);
Node* src2 = in(3);

// Lower the IR to constituents operations.
// SelectFromTwoVectorNode =
// (VectorBlend
// (VectorRearrange SRC1, INDEX)
// (VectorRearrange SRC2, NORM_INDEX)
// (VectorRearrange SRC1 INDEX)
// (VectorRearrange SRC2 NORM_INDEX)
// MASK)
//
// MASK = INDEX < num_elem
//
// This shall prevent an intrinsification failure and associated argument
// boxing penalties.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quick comment about how the mask is computed could be nice.
MASK = INDEX < num_elem

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jatin-bhateja very nice, thanks!

// Here, MASK lanes corresponding to INDEX values greater than or equal to
// vector length (VELEN) are set and are used to select the elements from
// second source (SRC2) vector.

auto lane_count_type = [&]() {
switch(elem_bt) {
case T_BYTE:
case T_SHORT:
case T_INT:
case T_FLOAT:
return static_cast<const Type*>(TypeInt::make(num_elem));
case T_DOUBLE:
case T_LONG:
return static_cast<const Type*>(TypeLong::make(num_elem));
default:
fatal("Unsupported vectortype (%s)", type2name(elem_bt));
return static_cast<const Type*>(nullptr);
}
};

auto make_integral_index_vec = [&](Node* index_vec) {
switch(elem_bt) {
case T_FLOAT:
return phase->transform(new VectorCastF2XNode(index_vec, TypeVect::make(T_INT, num_elem)));
const Type* lane_count_type = nullptr;
switch(elem_bt) {
case T_BYTE:
case T_SHORT:
case T_INT:
case T_FLOAT:
lane_count_type = TypeInt::make(num_elem);
break;
case T_DOUBLE:
case T_LONG:
lane_count_type = TypeLong::make(num_elem);
break;
case T_DOUBLE:
return phase->transform(new VectorCastD2XNode(index_vec, TypeVect::make(T_LONG, num_elem)));
default:
fatal("Unsupported vectortype (%s)", type2name(elem_bt));
break;
default:
return index_vec;
}
};
}

auto get_integal_type = [&](BasicType elem_bt) {
switch(elem_bt) {
case T_FLOAT: return T_INT;
case T_DOUBLE: return T_LONG;
default: return elem_bt;
}
};
BasicType integral_elem_bt = elem_bt;
Node* integral_index_vec = index_vec;
if (elem_bt == T_FLOAT) {
integral_elem_bt = T_INT;
integral_index_vec = phase->transform(new VectorCastF2XNode(index_vec, TypeVect::make(integral_elem_bt, num_elem)));
} else if (elem_bt == T_DOUBLE) {
integral_elem_bt = T_LONG;
integral_index_vec = phase->transform(new VectorCastD2XNode(index_vec, TypeVect::make(integral_elem_bt, num_elem)));
}

BasicType integral_elem_bt = get_integal_type(elem_bt);
int opc = VectorSupport::vop2ideal(VectorSupport::VECTOR_OP_SUB, integral_elem_bt);
int sopc = VectorNode::opcode(opc, integral_elem_bt);

BoolTest::mask pred = BoolTest::lt;
ConINode* pred_node = (ConINode*)phase->makecon(TypeInt::make(pred));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would as_ConI() be a better alternative to the (ConINode*) cast?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please at least add a comment why you are not following my suggestion. I feel like the work I put in to review is not being respected when comments are just silently resolved without any action or comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really do think that as_ConI() would be the right thing here. In product it is just a cast, and in debug at least we have an assert.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE

Copy link
Member Author

@jatin-bhateja jatin-bhateja Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just got overlooked @eme64, we should always respect reviewer's suggestions and should value the time they invest in polishing our patches, thanks again :-)

Node* lane_cnt = phase->makecon(lane_count_type());
Node* lane_cnt = phase->makecon(lane_count_type);
Node* bcast_lane_cnt_vec = phase->transform(VectorNode::scalar2vector(lane_cnt, num_elem, Type::get_const_basic_type(integral_elem_bt), false));
Node* integral_index_vec = make_integral_index_vec(index_vec);

// Comparison over integral vectors weeds out emitting additional
// instructions for checking special floating point values.
Expand All @@ -2171,21 +2166,22 @@ Node* VectorRearrangeNode::Ideal(PhaseGVN* phase, bool can_reshape) {
if (in(2)->Opcode() != Op_VectorUnbox &&
in(2)->Opcode() != Op_VectorLoadShuffle &&
Matcher::match_rule_supported_vector(Op_VectorRearrange, num_elem, elem_bt) &&
Matcher::vector_indexes_needs_massaging(elem_bt, num_elem)) {
auto get_integal_type = [&](BasicType elem_bt) {
switch(elem_bt) {
case T_FLOAT: return T_INT;
case T_DOUBLE: return T_LONG;
default: return elem_bt;
}
};
Matcher::vector_indexes_needs_pruning(elem_bt, num_elem)) {

BasicType integral_elem_bt = elem_bt;
if (elem_bt == T_FLOAT) {
integral_elem_bt = T_INT;
} else if (elem_bt == T_DOUBLE) {
integral_elem_bt = T_LONG;
}

// Targets emulating unsupported permutation for certain vector types
// may need to message the indexes to match the users intent.
// may need to massage the indexes to match the users intent.
// Lowering index vector to a bytevector followed by an explicit loadshuffle
// will bring the indexes in the consumable format.
int cast_opc = VectorCastNode::opcode(-1, elem_bt, true);
Node* pack_shuf = phase->transform(VectorCastNode::make(cast_opc, in(2), T_BYTE, num_elem));
const TypeVect* newvt = TypeVect::make(get_integal_type(elem_bt), num_elem);
const TypeVect* newvt = TypeVect::make(integral_elem_bt, num_elem);
Node* unpack_shuf = phase->transform(new VectorLoadShuffleNode(pack_shuf, newvt));
return new VectorRearrangeNode(in(1), unpack_shuf);
}
Expand Down
7 changes: 4 additions & 3 deletions src/hotspot/share/opto/vectornode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,6 @@ class VectorLongToMaskNode : public VectorNode {
virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
};


//-------------------------- Vector mask broadcast -----------------------------------
class MaskAllNode : public VectorNode {
public:
Expand Down Expand Up @@ -1615,10 +1614,12 @@ class VectorRearrangeNode : public VectorNode {
};


// Selects elements from second and third vector based on the indices held in
// first vector two input vectors based on the indexes held in first vector.
class SelectFromTwoVectorNode : public VectorNode {
public:
SelectFromTwoVectorNode(Node* in1, Node* in2, Node* in3, const TypeVect* vt)
: VectorNode(in1, in2, in3, vt) {}
SelectFromTwoVectorNode(Node* index, Node* src1, Node* src2, const TypeVect* vt)
: VectorNode(index, src1, src2, vt) {}

Node* Ideal(PhaseGVN* phase, bool can_reshape);
virtual int Opcode() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ static ByteVector compressHelper(Vector<Byte> v, VectorMask<Byte> m) {
return r;
}

static ByteVector selectFromHelper(Vector<Byte> v1, Vector<Byte> v2, Vector<Byte> v3) {
static ByteVector selectFromTwoVectorHelper(Vector<Byte> v1, Vector<Byte> v2, Vector<Byte> v3) {
int vlen = v1.length();
byte[] res = new byte[vlen];
byte[] vpayload1 = ((ByteVector)v1).vec();
Expand Down Expand Up @@ -2592,10 +2592,10 @@ final ByteVector selectFromTemplate(ByteVector v,
/*package-private*/
@ForceInline
final ByteVector selectFromTemplate(ByteVector v1, ByteVector v2) {
int twovectorlen = length() * 2;
ByteVector wrapped_indexes = this.lanewise(VectorOperators.AND, twovectorlen - 1);
int twoVectorLen = length() * 2;
ByteVector wrapped_indexes = this.lanewise(VectorOperators.AND, twoVectorLen - 1);
return (ByteVector)VectorSupport.selectFromTwoVectorOp(getClass(), byte.class, length(), wrapped_indexes, v1, v2,
(vec1, vec2, vec3) -> selectFromHelper(vec1, vec2, vec3)
(vec1, vec2, vec3) -> selectFromTwoVectorHelper(vec1, vec2, vec3)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ static DoubleVector compressHelper(Vector<Double> v, VectorMask<Double> m) {
return r;
}

static DoubleVector selectFromHelper(Vector<Double> v1, Vector<Double> v2, Vector<Double> v3) {
static DoubleVector selectFromTwoVectorHelper(Vector<Double> v1, Vector<Double> v2, Vector<Double> v3) {
int vlen = v1.length();
double[] res = new double[vlen];
double[] vpayload1 = ((DoubleVector)v1).vec();
Expand Down Expand Up @@ -2434,14 +2434,14 @@ final DoubleVector selectFromTemplate(DoubleVector v,
/*package-private*/
@ForceInline
final DoubleVector selectFromTemplate(DoubleVector v1, DoubleVector v2) {
int twovectorlen = length() * 2;
int twoVectorLen = length() * 2;
DoubleVector wrapped_indexes = this.convert(VectorOperators.D2I, 0)
.lanewise(VectorOperators.AND, twovectorlen - 1)
.lanewise(VectorOperators.AND, twoVectorLen - 1)
.reinterpretAsInts()
.convert(VectorOperators.I2D, 0)
.reinterpretAsDoubles();
return (DoubleVector)VectorSupport.selectFromTwoVectorOp(getClass(), double.class, length(), wrapped_indexes, v1, v2,
(vec1, vec2, vec3) -> selectFromHelper(vec1, vec2, vec3)
(vec1, vec2, vec3) -> selectFromTwoVectorHelper(vec1, vec2, vec3)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ static FloatVector compressHelper(Vector<Float> v, VectorMask<Float> m) {
return r;
}

static FloatVector selectFromHelper(Vector<Float> v1, Vector<Float> v2, Vector<Float> v3) {
static FloatVector selectFromTwoVectorHelper(Vector<Float> v1, Vector<Float> v2, Vector<Float> v3) {
int vlen = v1.length();
float[] res = new float[vlen];
float[] vpayload1 = ((FloatVector)v1).vec();
Expand Down Expand Up @@ -2446,14 +2446,14 @@ final FloatVector selectFromTemplate(FloatVector v,
/*package-private*/
@ForceInline
final FloatVector selectFromTemplate(FloatVector v1, FloatVector v2) {
int twovectorlen = length() * 2;
int twoVectorLen = length() * 2;
FloatVector wrapped_indexes = this.convert(VectorOperators.F2I, 0)
.lanewise(VectorOperators.AND, twovectorlen - 1)
.lanewise(VectorOperators.AND, twoVectorLen - 1)
.reinterpretAsInts()
.convert(VectorOperators.I2F, 0)
.reinterpretAsFloats();
return (FloatVector)VectorSupport.selectFromTwoVectorOp(getClass(), float.class, length(), wrapped_indexes, v1, v2,
(vec1, vec2, vec3) -> selectFromHelper(vec1, vec2, vec3)
(vec1, vec2, vec3) -> selectFromTwoVectorHelper(vec1, vec2, vec3)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ static IntVector compressHelper(Vector<Integer> v, VectorMask<Integer> m) {
return r;
}

static IntVector selectFromHelper(Vector<Integer> v1, Vector<Integer> v2, Vector<Integer> v3) {
static IntVector selectFromTwoVectorHelper(Vector<Integer> v1, Vector<Integer> v2, Vector<Integer> v3) {
int vlen = v1.length();
int[] res = new int[vlen];
int[] vpayload1 = ((IntVector)v1).vec();
Expand Down Expand Up @@ -2577,10 +2577,10 @@ final IntVector selectFromTemplate(IntVector v,
/*package-private*/
@ForceInline
final IntVector selectFromTemplate(IntVector v1, IntVector v2) {
int twovectorlen = length() * 2;
IntVector wrapped_indexes = this.lanewise(VectorOperators.AND, twovectorlen - 1);
int twoVectorLen = length() * 2;
IntVector wrapped_indexes = this.lanewise(VectorOperators.AND, twoVectorLen - 1);
return (IntVector)VectorSupport.selectFromTwoVectorOp(getClass(), int.class, length(), wrapped_indexes, v1, v2,
(vec1, vec2, vec3) -> selectFromHelper(vec1, vec2, vec3)
(vec1, vec2, vec3) -> selectFromTwoVectorHelper(vec1, vec2, vec3)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ static LongVector compressHelper(Vector<Long> v, VectorMask<Long> m) {
return r;
}

static LongVector selectFromHelper(Vector<Long> v1, Vector<Long> v2, Vector<Long> v3) {
static LongVector selectFromTwoVectorHelper(Vector<Long> v1, Vector<Long> v2, Vector<Long> v3) {
int vlen = v1.length();
long[] res = new long[vlen];
long[] vpayload1 = ((LongVector)v1).vec();
Expand Down Expand Up @@ -2443,10 +2443,10 @@ final LongVector selectFromTemplate(LongVector v,
/*package-private*/
@ForceInline
final LongVector selectFromTemplate(LongVector v1, LongVector v2) {
int twovectorlen = length() * 2;
LongVector wrapped_indexes = this.lanewise(VectorOperators.AND, twovectorlen - 1);
int twoVectorLen = length() * 2;
LongVector wrapped_indexes = this.lanewise(VectorOperators.AND, twoVectorLen - 1);
return (LongVector)VectorSupport.selectFromTwoVectorOp(getClass(), long.class, length(), wrapped_indexes, v1, v2,
(vec1, vec2, vec3) -> selectFromHelper(vec1, vec2, vec3)
(vec1, vec2, vec3) -> selectFromTwoVectorHelper(vec1, vec2, vec3)
);
}

Expand Down
Loading