This is an archive of the discontinued LLVM Phabricator instance.

[fir] Add fir.select and fir.select_rank FIR to LLVM IR conversion patterns
ClosedPublic

Authored by clementval on Nov 3 2021, 1:47 AM.

Details

Summary

The fir.select and fir.select_rank are lowered to a if-then-else
ladder.

This patch is part of the upstreaming effort from fir-dev branch.

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>

Diff Detail

Event Timeline

clementval created this revision.Nov 3 2021, 1:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2021, 1:47 AM
Herald added a subscriber: mehdi_amini. · View Herald Transcript
clementval requested review of this revision.Nov 3 2021, 1:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2021, 1:47 AM
clementval added inline comments.Nov 4 2021, 8:09 AM
flang/lib/Optimizer/CodeGen/CodeGen.cpp
212

Just realized the LLVM IR dialect has the SwitchOp now. I'll rewrite the conversion to make use of it.

clementval updated this revision to Diff 384869.Nov 4 2021, 2:45 PM

Convert to llvm.switch instead of if-then-else ladder

clementval updated this revision to Diff 384871.Nov 4 2021, 2:48 PM

Remove unused code after switch to llvm.switch

mehdi_amini accepted this revision.Nov 4 2021, 6:08 PM
mehdi_amini added inline comments.
flang/include/flang/Optimizer/Dialect/FIROps.td
487

If this is just about having a get prepended, there is an option in ODS to do this universally (since https://reviews.llvm.org/D111033 ).
I don't think it is scalable to just alias manually every possible accessor.

You can just add let emitAccessorPrefix = kEmitAccessorPrefix_Both; in the Dialect ODS definition to get both forms generated.

flang/lib/Optimizer/CodeGen/CodeGen.cpp
181

Can we just use int? (or int64_t)
(The code with the decltype seems just really unusual to me)

183

Seems like a missing accessor on fir_SwitchTerminatorOp in the ODS file?

185
198

Attributes are value types

This revision is now accepted and ready to land.Nov 4 2021, 6:08 PM
clementval updated this revision to Diff 385001.Nov 5 2021, 2:58 AM
clementval marked 4 inline comments as done.

Address comments