This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Replace a not of a comparison with appropriate comparison
ClosedPublic

Authored by wsmoses on May 1 2021, 9:17 PM.

Diff Detail

Event Timeline

wsmoses created this revision.May 1 2021, 9:17 PM
wsmoses requested review of this revision.May 1 2021, 9:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 1 2021, 9:17 PM
rriddle added inline comments.May 1 2021, 9:25 PM
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
2757

Please use m_Constant to match constants.

2766

Are all of these mlir:: necessary? If not, please drop them.

mlir/test/Dialect/Standard/canonicalize.mlir
312

Can you add tests for the other cases?

wsmoses updated this revision to Diff 342215.May 1 2021, 9:42 PM

Test all integer comparisons

chelini added inline comments.May 3 2021, 12:22 AM
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
2751

I would make this top-level comment more generic, something like Replace a not of a comparison operation, for example: not(cmp eq A, B) => cmp ne A, B.

mlir/test/Dialect/Standard/canonicalize.mlir
321

No newline.

ftynse requested changes to this revision.May 3 2021, 12:28 AM
ftynse added inline comments.
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
2751

And also mention that "not" is in practice "xor 1".

2764

The i / 1 - i trick deserves a comment. (Personally, I would have written a function and just called it twice).

2766

I suppose you want to continue here rather than error out. Otherwise you seem to be missing on a valid an optimizable case of xor %value, 1 : i1.

This revision now requires changes to proceed.May 3 2021, 12:28 AM
wsmoses updated this revision to Diff 342572.May 3 2021, 3:43 PM

Address comments

mehdi_amini added inline comments.May 3 2021, 5:16 PM
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
2759

Please avoid i and other single letter variable name and find something meaningful instead. Even operand_id would be better.

Also, in general we don't need to have such loop. Instead we should canonicalize commutative operations to have constant always on the same side.

rriddle added inline comments.May 3 2021, 5:19 PM
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
2759

(operandId given we use camelCase variables)

wsmoses updated this revision to Diff 342607.May 3 2021, 5:38 PM

Remove for loop

wsmoses marked 9 inline comments as done.May 3 2021, 9:38 PM
ftynse accepted this revision.May 4 2021, 2:27 AM
ftynse added inline comments.
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
2752

Nit: trailing dot please.

2760

Nit: let's mention that we expect constants to have been canonicalized to be the second operand.

This revision is now accepted and ready to land.May 4 2021, 2:27 AM