This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Generalize select to arithmetic canonicalization
ClosedPublic

Authored by wsmoses on Jan 7 2022, 2:27 PM.

Details

Summary

Given a select whose result is an i1, we can eliminate the conditional in the select completely by adding a few arithmetic operations.

Diff Detail

Event Timeline

wsmoses created this revision.Jan 7 2022, 2:27 PM
wsmoses requested review of this revision.Jan 7 2022, 2:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 7 2022, 2:27 PM
bondhugula requested changes to this revision.Jan 9 2022, 4:28 AM
bondhugula added a subscriber: bondhugula.
bondhugula added inline comments.
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
833–840

Always avoid nesting multiple IR-creating calls. It can lead to an unpredictable "order of evaluation" dependent output that is sensitive to compilers, their versions, and options.

mlir/test/Dialect/Standard/canonicalize.mlir
102–104

An unstable/unknown order isn't desirable.

This revision now requires changes to proceed.Jan 9 2022, 4:28 AM
wsmoses updated this revision to Diff 398449.Jan 9 2022, 11:14 AM

Address comments

Given a select whose result is an i1, we can eliminate the conditional branch completely by adding a few arithmetic operations.

Nit: Could you clarify which conditional branch you are referring to here? Is it the conditional branch in machine instruction for those architectures without a select instruction?

mlir/lib/Dialect/StandardOps/IR/Ops.cpp
816

Nit: This comment probably needs an update.

wsmoses edited the summary of this revision. (Show Details)Jan 9 2022, 3:15 PM
wsmoses updated this revision to Diff 398464.Jan 9 2022, 3:16 PM

Address nits

ftynse accepted this revision.Jan 10 2022, 7:25 AM
This revision is now accepted and ready to land.Jan 10 2022, 7:25 AM
This revision was automatically updated to reflect the committed changes.