This patch implements lowering for the Fortran 2008 bit-population count intrinsics POPCNT, POPPAR, LEADZ and TRAILZ.
POPCNT, LEADZ and TRAILZ are implemented using calls to the corresponding LLVM intrinsic.
POPVAR is implemented in terms of POPCNT.
Paths
| Differential D129584
Lower F08 bit-population count intrinsics ClosedPublic Authored by tarunprabhu on Jul 12 2022, 12:29 PM.
Details Summary This patch implements lowering for the Fortran 2008 bit-population count intrinsics POPCNT, POPPAR, LEADZ and TRAILZ. POPCNT, LEADZ and TRAILZ are implemented using calls to the corresponding LLVM intrinsic. POPVAR is implemented in terms of POPCNT.
Diff Detail
Event Timeline
Comment Actions Use LLVM intrinsics instead of calculating POPCNT by hand. Add implementation and tests for LEADZ and TRAILZ in addition to POPCNT and POPPAR since they are also related. Comment Actions The math dialect has operations that model leadz, trailz, pop etc. There exists a conversion from math dialect to llvm (https://github.com/llvm/llvm-project/blob/4ae254e48850033f4e441a28fb28ae27d63ea458/mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp#L87). Using these ops might be useful since the might have some transformations/folding, the existence of vector versions might help vectorisation in the future.
Comment Actions Updated patch to use mlir population operators for leadz, popcnt and trailz instead of calling the LLVM intrinsics. Removed the folding tests from this patch. kiranchandramohan added inline comments.
Comment Actions Create the call to the MLIR ctpop, leadz and trailz instructions directly instead of using genMathOp. Use the flang driver in the tests. Comment Actions LGTM. Thanks for all the changes. Please wait a day before submitting in case there are further comments from others.
This revision is now accepted and ready to land.Jul 13 2022, 3:41 PM
Closed by commit rGccfee46bc723: [flang] Lower F08 bit population count intrinsics (authored by tarunprabhu). · Explain WhyJul 21 2022, 10:09 PM This revision was automatically updated to reflect the committed changes. Comment Actions
@PeteSteinfeld, no I do not. If you can file a bug report, I can investigate the failure. Comment Actions
Thanks, @tarunprabhu . I'm all set for now.
Revision Contents
Diff 446706 flang/lib/Lower/IntrinsicCall.cpp
flang/test/Lower/Intrinsics/leadz.f90
flang/test/Lower/Intrinsics/popcnt.f90
flang/test/Lower/Intrinsics/poppar.f90
flang/test/Lower/Intrinsics/trailz.f90
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The genMathOp function seems to switch between the libm version and the Math dialect Op version based on whether the setting of mathRuntimeVersion is precise or not. I believe the mathRuntimeVersion is for floating point intrinsics and probably not applicable for integer intrinsics. Adding @vzakhari for an opinion on this.