This is an archive of the discontinued LLVM Phabricator instance.

[flang] add hlfir.any intrinsic
ClosedPublic

Authored by jacob-crawley on May 5 2023, 8:10 AM.

Details

Summary

Adds a HLFIR operation for the ANY intrinsic according to the
design set out in flang/docs/HighLevel.md

Diff Detail

Event Timeline

jacob-crawley created this revision.May 5 2023, 8:10 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 5 2023, 8:10 AM
jacob-crawley requested review of this revision.May 5 2023, 8:10 AM
flang/include/flang/Optimizer/HLFIR/HLFIROps.td
320

FastMathInterface is not applicable for logical types/intrinsics.

tblah added inline comments.May 9 2023, 2:39 AM
flang/include/flang/Optimizer/HLFIR/HLFIROps.td
328

This checks the type with isMaskArgument(), which explicitly allows scalar logicals. Scalars are not allowed here by the standard, and your verifier assumes that the argument is an array (casting with ::cast<fir::SequenceType>). You should write a new type predicate which only allows arrays of logicals.

flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
457

numTy is not a good name here. How about logicalTy (to make sure the returned logical is of the same kind as the input logical).

474–476

This check can be factored outside of the if statement

Thanks for working on this!

flang/include/flang/Optimizer/HLFIR/HLFIROps.td
320

I am not familiar with this interface, but I agree it is weird outside of operations that may do floating-point arithmetic (adding @vzakhari in the discussion since he requested it for hlfir.sum in https://reviews.llvm.org/D142897#inline-1382331).

334

I am just noticing it now, but I think that for intrinsics that may return simple scalars, we should not use hlfir_ExprType, this adds extra abstraction that is not needed outside of aggregate and array types, and I think some pieces in lowering may not like it, or will place the expr in memory in order to get back the scalar logical via a load.

So this should probably be AnyFortranValue with a check that this is a logical or logical hlfi.expr inside the verifier.

Since this also applies to Sum and, Product, I am also OK with first checking this in a changing that for all of them at once.

flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
454–456

You cannot assume yet that you will have a sequence here since I think AnyFortranLogicalOrI1ArrayObject accepts scalars.

You either need to first verify that here, or to add a AnyFortranLogicalArrayObject predicate and use it instead of AnyFortranLogicalOrI1ArrayObject.

jacob-crawley marked 6 inline comments as done.

Thanks for the reviews.

  • Added a new predicate 'AnyFortranLogicalArrayObject'
  • Removed referenes to the FastMathInterface
  • Renamed 'numTy' variable to 'logicalTy'
jacob-crawley added inline comments.May 9 2023, 6:15 AM
flang/include/flang/Optimizer/HLFIR/HLFIROps.td
334

Sure, I agree that using AnyFortranValue with an extra check may be simpler for these intrinsics.

I'd be happy to add that change in a different commit .

tblah accepted this revision.May 9 2023, 6:17 AM

LGTM. Thanks for addressing the comments

This revision is now accepted and ready to land.May 9 2023, 6:17 AM
vzakhari added inline comments.May 9 2023, 8:59 AM
flang/include/flang/Optimizer/HLFIR/HLFIROps.td
330

Please remove the fastmath attr.

removed missed fastmath attr line in AnyOp defintion

jacob-crawley marked an inline comment as done.May 9 2023, 9:17 AM