Skip to content

Implement new vector opcodes - #6458

Merged
0xdaryl merged 3 commits into
eclipse-omr:masterfrom
gita-omr:pr_vector_opcodes
Apr 19, 2022
Merged

0xdaryl merged 3 commits into
eclipse-omr:masterfrom
gita-omr:pr_vector_opcodes

Conversation

@gita-omr

@gita-omr gita-omr commented Apr 5, 2022

Copy link
Copy Markdown
Contributor
  • introduce VectorOperations enum(vadd and vfma for now)
  • the set of vector opcodes is a product of vector operations and vector types
  • vector opcodes are generated at runtime and stored in IlOpCode class
  • all OMR tables contain entries for vector operations following non-vector opcodes

@gita-omr

gita-omr commented Apr 5, 2022

Copy link
Copy Markdown
Contributor Author

Fixed line endings in a new file.

@gita-omr

gita-omr commented Apr 5, 2022

Copy link
Copy Markdown
Contributor Author

Jenkins build all

@gita-omr
gita-omr force-pushed the pr_vector_opcodes branch from 9c866ca to 933294d Compare April 5, 2022 04:30
@gita-omr

gita-omr commented Apr 5, 2022

Copy link
Copy Markdown
Contributor Author

Fixed mistake in extra parameter in TR_ASSERT.

@gita-omr

gita-omr commented Apr 5, 2022

Copy link
Copy Markdown
Contributor Author

Jenkins build all

@gita-omr
gita-omr force-pushed the pr_vector_opcodes branch from 933294d to e2aa009 Compare April 5, 2022 06:49
- introduce VectorOperations enum(vadd and vfma for now)
- the set of vector opcodes is a product of vector operations and vector types
- vector opcodes are generated at runtime and stored in IlOpCode class
- all OMR tables contain entries for vector operations following non-vector opcodes
@gita-omr
gita-omr force-pushed the pr_vector_opcodes branch from e2aa009 to 24c4aa8 Compare April 5, 2022 06:52
@gita-omr

gita-omr commented Apr 5, 2022

Copy link
Copy Markdown
Contributor Author

@0xdaryl could you please review and approve the common part?
@Akira1Saitoh @r30shah @BradleyWood @IBMJimmyk could you please review and approve aarch64, z, x, and p files correspondingly?

@jdmpapin @Leonardo2718 @mstoodle @vijaysun-omr : fyi

Please kindly provide your comments by the end of the week so that we can target mid next week (Arpil 13) for the merge?


TR::Register*
OMR::X86::I386::TreeEvaluator::vfmaEvaluator(TR::Node *node, TR::CodeGenerator *cg)
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a reason to define these implementations specific to ia32/amd64? As far as I know, intel vfma instructions should work on 32-bit as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I just follow an example of vdsqrt. In which class should I define vfma so that it works for both? @BradleyWood

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was just referring to commoning it in compiler/x/codegen/OMRTreeEvaluator

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the evaluator needs to be defined in both inOMR::X86::AMD64::TreeEvaluator and in OMR::X86::I386::TreeEvaluator classes to avoid linkage errors. Currently they are both unimplemented. I think it's better to do the commoning when they are actually implemented. This PR is just an example how to add a new vector opcode.

Comment thread compiler/x/codegen/OMRTreeEvaluator.cpp Outdated
if (OMR::ILOpCode::isVectorOpCode(opcode) && OMR::ILOpCode::getVectorOperation(opcode) == OMR::vadd)
{
arithmetic = BinaryArithmeticAdd;
break;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps this can be a switch statement to discourage large chains of if statements in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed

Comment thread compiler/x/codegen/OMRCodeGenerator.cpp Outdated
TR::DataType et = ot.getVectorElementType();

if (et == TR::Int8 || et == TR::Int16 || et == TR::Int32 || et == TR::Int64 || et == TR::Float || et == TR::Double)
return true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't this all the data types? You can simplify:

return ot.getVectorLength() == TR::VectorLength128; // all types supported for vadd128

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed these are all the types. I did not notice it while moving existing code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done


if (opcode.isVectorOpCode() && opcode.getVectorOperation() == OMR::vadd)
{
TR::DataType ot = opcode.getVectorResultDataType();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't length and opcode.getVectorResultDataType() be equal? Also, for the old vector opcodes, the vector length is assumed to be 128, so do we really need that argument?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good points. I was thinking of removing that argument when we remove all old style opcodes. But maybe you are right, we can remove it now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done


TR::DataType et = ot.getVectorElementType();

if (et == TR::Int8 || et == TR::Int16 || et == TR::Int32 || et == TR::Int64 || et == TR::Float || et == TR::Double)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The same comment as in https://github.com/eclipse/omr/pull/6458/files#r843332926. It appears that all element types are listed here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, I just copied the old code. I will simplify.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@gita-omr
gita-omr force-pushed the pr_vector_opcodes branch 3 times, most recently from 1dcf105 to 3592e50 Compare April 7, 2022 00:32
Comment thread compiler/z/codegen/OMRCodeGenerator.cpp Outdated
return false;
}

if (opcode.isVectorOpCode() && opcode.getVectorOperation() == OMR::vadd)

@r30shah r30shah Apr 7, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am thinking on how we make this part more extensible? i.e, when we start adding support for other vector operations as well. If the opcode is Vector Opcode, it might be better if we use switch case similar to how it is used for old vector types. That would make adding new types easier and cleaner.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When we remove all old vector opcodes we will have only one switch. Maybe better to leave it till then?

@gita-omr gita-omr Apr 7, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And if (opcode.isVectorOpCode()) will soon be gone as well since all vector opcodes will return true.

@r30shah r30shah Apr 7, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we planning to replace old opcode with new opcodes together in future or incrementally?
If we are planning together then we can leave it till then but in case of incrementally adding them (For example, OMR::vsub, OMR::vmul , etc), we will have to stick them to above if condition right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, just looked at it more careful. It will not cause any nested switches, so sure, I will change to a single case switch to set a good example :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed to a switch on all platforms.

@gita-omr

gita-omr commented Apr 7, 2022

Copy link
Copy Markdown
Contributor Author

Just wanted to bring to the attention of the reviewers that it's important to make sure that all the tables that rely on the number of opcodes or their order need to be checked. I think I found all such places but please let me know if you can think of anything else.

@gita-omr
gita-omr force-pushed the pr_vector_opcodes branch from 3592e50 to 27833a4 Compare April 7, 2022 20:01

if (ot.getVectorLength() != TR::VectorLength128) return false;

swtich (opcode.getVectorOperation())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Typo: switch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread compiler/codegen/OMRCodeGenerator.hpp Outdated
class TreeEvaluatorFunctionPointerTable
{
private:
static TR_TreeEvaluatorFunctionPointer table[];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since you are wrapping this table with another class, perhaps now is the time to drop the TR_ prefix from its name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TR_TreeEvaluatorFunctionPointer was and still is defined in another file, outside of any class, as:

typedef TR::Register *(* TR_TreeEvaluatorFunctionPointer)(TR::Node *node, TR::CodeGenerator *codeGen);

I am not sure yet what would be the best place for it...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I found a better place: just before the class that uses it is defined.

Comment thread compiler/il/OMRDataTypes.cpp Outdated
// to avoid any race conditions, initialize all vector names once,
// as soon as first one is requested
static bool staticallyInitialized = initVectorNames();
static bool staticallyInitialized = initVectorNames();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove extra indent space (unless there's a reason for it that's not apparent to me).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed the typo

Comment thread compiler/il/OMRILOps.hpp Outdated
public:

// The class is capable of storing "hidden" vector opcodes and provides an interface
// for creating and quiering them

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sp. : querying

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread compiler/il/OMRILOps.hpp Outdated
// The class is capable of storing "hidden" vector opcodes and provides an interface
// for creating and quiering them
// Vector operations that return a non-vector type(e.g. reduction) or for which result
// and source types are different(e.g. conversion) will be handled later

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you add a space before the ( in the above two lines please?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread compiler/il/OMRILOps.hpp Outdated
*/
static ILOpCode createVectorOpCode(VectorOperation operation, DataType resultVectorType)
{
static_assert(NumAllIlOps < ((long long)1 << (sizeof(TR::ILOpCodes)*8)), "Number of scalar and vector opcodes does not fit into TR::ILOpCodes\n");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a reason to use long long here instead of the more conventional uint64_t throughout the code base?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, good point. Will change.

Comment thread compiler/il/OMRILOps.hpp Outdated
*/
static VectorOperation getVectorOperation(ILOpCode op)
{
TR_ASSERT_FATAL(isVectorOpCode(op), "getVectOroperation() can only be called on vector opcode\n");

@0xdaryl 0xdaryl Apr 8, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sp. : getVectorOperation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed. Thanks.

Comment thread compiler/il/OMRILOps.hpp Outdated
case TR::iadd: return ILOpCode::createVectorOpCode(OMR::vadd, TR::DataType::createVectorType(TR::Int32, vectorLength)).getOpCodeValue();
case TR::ladd: return ILOpCode::createVectorOpCode(OMR::vadd, TR::DataType::createVectorType(TR::Int64, vectorLength)).getOpCodeValue();
case TR::fadd: return ILOpCode::createVectorOpCode(OMR::vadd, TR::DataType::createVectorType(TR::Float, vectorLength)).getOpCodeValue();
case TR::dadd: return ILOpCode::createVectorOpCode(OMR::vadd, TR::DataType::createVectorType(TR::Double, vectorLength)).getOpCodeValue();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since there is already a local opcode set to the scalar opcode (L1353-1354), I think this can be simplified (and generate less code) as:

case TR::badd:
case TR::sadd:
case TR::iadd: 
case TR::ladd: 
case TR::fadd:
case TR::dadd:
   return ILOpCode::createVectorOpCode(OMR::vadd, TR::DataType::createVectorType(opcode.getDataType(), vectorLength)).getOpCodeValue();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, that will be better. Will change

Comment thread compiler/optimizer/OMRSimplifier.cpp Outdated
static_assert(TR::NumIlOps ==
(sizeof(simplifierOpts) / sizeof(simplifierOpts[0])),
"simplifierOpts is not the correct size");
extern const SimplifierPtrTable simplifierOpts;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this name should be made consistent with the CodeGenerator TreeEvaluatorFunctionPointerTable you created earlier (i.e., expand the Ptr)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, I just added "Table" to the old name. Will make them consistent.

typedef TR::Node* (* ValuePropagationPtr)(OMR::ValuePropagation *, TR::Node *);
extern const ValuePropagationPtr constraintHandlers[];

class ValuePropagationPtrTable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this name should be made consistent with the CodeGenerator TreeEvaluatorFunctionPointerTable you created earlier (i.e., expand the Ptr)

@gita-omr gita-omr Apr 9, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Similar to the Simplifier I just added "Table" to the existing name. I will make them consistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@gita-omr
gita-omr force-pushed the pr_vector_opcodes branch from 27833a4 to 65ed745 Compare April 9, 2022 04:33
- new opcodes will have length encoded in them and old ones assume 128
@gita-omr
gita-omr force-pushed the pr_vector_opcodes branch 3 times, most recently from 6168f31 to 4e75d72 Compare April 9, 2022 19:05
@gita-omr

gita-omr commented Apr 9, 2022

Copy link
Copy Markdown
Contributor Author

Jenkins build all

Comment thread compiler/p/codegen/OMRCodeGenerator.cpp Outdated
TR::DataType et = ot.getVectorElementType();

if (self()->comp()->target().cpu.isAtLeast(OMR_PROCESSOR_PPC_P8) &&
opcode.getVectorOperation() == OMR::vadd && dt == TR::Int64)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is supposed to check et against TR::Int64?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good find! Currently, they are the same and dt will be removed when we remove all old (typeless) vector opcodes. But let me change just for clarity.

@gita-omr
gita-omr force-pushed the pr_vector_opcodes branch from 4e75d72 to a6ccacf Compare April 12, 2022 19:19
@gita-omr

Copy link
Copy Markdown
Contributor Author

Addressed latest comments.

@IBMJimmyk

Copy link
Copy Markdown
Contributor

I looked over the P sections of the code and they looked good to me.

@0xdaryl

0xdaryl commented Apr 18, 2022

Copy link
Copy Markdown
Contributor

Jenkins build all

@0xdaryl 0xdaryl self-assigned this Apr 18, 2022
@0xdaryl

0xdaryl commented Apr 18, 2022

Copy link
Copy Markdown
Contributor

Last call for review comments. This will be merged later this evening unless there are any new concerns raised.

@0xdaryl

0xdaryl commented Apr 18, 2022

Copy link
Copy Markdown
Contributor

Jenkins build zos

@0xdaryl
0xdaryl merged commit 2a68fa0 into eclipse-omr:master Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants