This is an archive of the discontinued LLVM Phabricator instance.

[flang][Evaluate] Fold DBLE
ClosedPublic

Authored by rogfer01 on Mar 22 2022, 1:31 AM.

Details

Summary

We can reuse the folding of REAL.

Diff Detail

Event Timeline

rogfer01 created this revision.Mar 22 2022, 1:31 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
rogfer01 requested review of this revision.Mar 22 2022, 1:31 AM

I was wondering why similar intrinsics SNGL and FLOAT work already but they seem to be lowered earlier to REAL, does this make sense?

(Also this is my first patch for flang, so if I'm missing something very obvious please let me know. Thanks!)

jeanPerier accepted this revision.Mar 22 2022, 2:31 AM

Thanks for the patch.

I was wondering why similar intrinsics SNGL and FLOAT work already but they seem to be lowered earlier to REAL, does this make sense?

Yes, SNGL is a specific intrinsic (defined in section 16.8 in Fortran 2018 standard), while DBLE is a generic intrinsic (defined in section 16.9). Intrinsic procedure call resolution (Probe in lib/Evaluate/intrinsics.cpp) replaces specific names by the related generic names. So SGNL is replaced by REAL there, but DBLE is not. So your patch in folding makes sense to me.

flang/test/Evaluate/fold-dble.f90
7

test_folding.py is testing that parameters names text_xxx (with xxx being any string) folds to .true.. Your test currently checks that dble is folded, but not that it is folded correctly. To make your test more thorough, you could add to the module definitions:

logical, parameter :: test_dble_1 = ntotal_f == real(nx*ny*nz, kind(0.0D0))
logical, parameter :: test_dble_2 = kind(dble(nx)) == kind(0.0D0)
This revision is now accepted and ready to land.Mar 22 2022, 2:31 AM
klausler accepted this revision.Mar 22 2022, 9:04 AM

Yes, SNGL is a specific intrinsic (defined in section 16.8 in Fortran 2018 standard), while DBLE is a generic intrinsic (defined in section 16.9). Intrinsic procedure call resolution (Probe in lib/Evaluate/intrinsics.cpp) replaces specific names by the related generic names. So SGNL is replaced by REAL there, but DBLE is not. So your patch in folding makes sense to me.

OK. Thanks a lot for the clarification, @jeanPerier.

rogfer01 updated this revision to Diff 417503.Mar 22 2022, 10:53 PM

ChangeLog:

  • Improve the test with assertions verified by test_folding.py as suggested
rogfer01 marked an inline comment as done.Mar 22 2022, 10:54 PM
jeanPerier accepted this revision.Mar 23 2022, 7:28 AM
This revision was automatically updated to reflect the committed changes.