This is an archive of the discontinued LLVM Phabricator instance.

[mlir][emitc] Add comparison operation
ClosedPublic

Authored by simon-camp on Aug 17 2023, 6:23 AM.

Details

Summary

This adds a comparison operation to EmitC which supports ==, !=, <=, <, >=, >, <=>.

Diff Detail

Event Timeline

simon-camp created this revision.Aug 17 2023, 6:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 17 2023, 6:23 AM
simon-camp requested review of this revision.Aug 17 2023, 6:23 AM

Updating D158180: [mlir][emitc] Add comparison operation

Overall looks good

mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
181

It may read better without this comma, else the predicate looks like an operand to me. WDYT?

mlir/include/mlir/Dialect/EmitC/IR/EmitCAttributes.td
39

I see three-way most commonly used - but didn't check spec.

mlir/lib/Target/Cpp/TranslateToCpp.cpp
321

Errors follow convention of being sentence fragments (start lower case, no trailing punctuation)

Updating D158180: [mlir][emitc] Add comparison operation

Address review comments.

simon-camp marked an inline comment as done.Aug 22 2023, 7:06 AM
simon-camp added inline comments.
mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
181

I have no strong opinion on this. I just copied what was in the arith dialect and that one has the comma.

mlir/include/mlir/Dialect/EmitC/IR/EmitCAttributes.td
39

A hyphen won't work as this name is also used as an enum member in the ODS generated code. So I've gone with an underscore.

Updating D158180: [mlir][emitc] Add comparison operation

Code formatting

jpienaar accepted this revision.Aug 29 2023, 5:04 AM

Thanks, makes sense to keep consistent with arith

mlir/test/Target/Cpp/comparison_operators.mlir
6

Mixed types are supported, how about mixing these a bit? i32 compare with f32, f32 with i64, i64 with unsigned, ... with custom? The number of compares remain the same as you are testing the enums, but contrary to arith dialect these can be mixed.

16

Shouldn't the second V0 here not be captured?

This revision is now accepted and ready to land.Aug 29 2023, 5:04 AM

Updating D158180: [mlir][emitc] Add comparison operation

Mix up operand types and don't capture arguments multiple times.

simon-camp marked 2 inline comments as done.Aug 29 2023, 7:52 AM
simon-camp added inline comments.
mlir/test/Target/Cpp/comparison_operators.mlir
6

I shuffled some arguments around and varied the return type as well.

16

Yes, changed this to capture only the first occurence of an argument.

This revision was automatically updated to reflect the committed changes.