This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] fix regression in inline elementals
ClosedPublic

Authored by tblah on May 23 2023, 4:48 AM.

Details

Summary

InlineElementals created a regression when inlining elemental
expressions where the type of the result of the hlfir.apply does not
match the hlfir.yield.

This patch ensures the pass doesn't match in these cases, fixing the
regression.

It isn't clear to me what the /right/ solution is:

  • Is it actually valid for the hlfir.apply to have a different type (even just different array bounds?). Should this be enforced in the verifier?
  • Inserting a convert if these types don't match doesn't work because fir.convert doesn't know how to convert a hlfir.expr. Should this be added?

Test case is from @vzakhari

Diff Detail

Event Timeline

tblah created this revision.May 23 2023, 4:48 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
tblah requested review of this revision.May 23 2023, 4:48 AM
jeanPerier accepted this revision.May 23 2023, 11:38 PM

Thanks, LGTM to be safe, but I agree with your points, this should not have happened in the first place. It looks the issue is not with the hlfir.apply itself, but the hlfir.elemental that has a "different" element type from its hlfir.yield_element:

%23 = hlfir.elemental %22 typeparams %c6 : (!fir.shape<3>, index) -> !hlfir.expr<?x?x?x!fir.char<1,?>> {
^bb0(%arg0: index, %arg1: index, %arg2: index):
  //.....
  %42 = hlfir.concat %40, %41 len %c6 : (!fir.ref<!fir.char<1,5>>, !fir.ref<!fir.char<1>>, index) -> !hlfir.expr<!fir.char<1,6>>
  hlfir.yield_element %42 : !hlfir.expr<!fir.char<1,6>>
}

Typical character length issue. I will try to fix lowering and add a verifier for the hlfir.elemental.

Inserting a convert if these types don't match doesn't work because fir.convert doesn't know how to convert a hlfir.expr. Should this be added?

I would stay away from this right now because this would likely imply creating a copy of potentially big values.

This revision is now accepted and ready to land.May 23 2023, 11:38 PM
vzakhari accepted this revision.May 24 2023, 1:09 PM

Thank you for the change, @tblah!

This revision was automatically updated to reflect the committed changes.