This is an archive of the discontinued LLVM Phabricator instance.

[Flang] Temporary fix for conversion materialization
ClosedPublic

Authored by kiranchandramohan on Jun 7 2022, 6:12 AM.

Details

Summary

Simply add a source and target materialization handler that do nothing
and that override the default handlers that would add illegal
LLVM::DialectCastOp otherwise.

This is the simplest workaround, but not an actual fix, something may be
inconsistent after D82831 (most likely fir lowering to llvm happens in a
way that mlir infrastructure is not expecting in D82831).

Here is a minimal reproducer of what the issue was:

func @foop(%a : !fir.real<4>) -> ()
func @bar(%a : !fir.real<2>) {
  %1 = fir.convert %a : (!fir.real<2>) -> !fir.real<4>
  call @foop(%1) : (!fir.real<4>) -> ()
  return
}

tco -o - output was:

error: 'llvm.mlir.cast' op type must be non-index integer types, float types, or vector of mentioned types.
llvm.func @foop(!llvm.float)
llvm.func @bar(%arg0: !llvm.half) {
  %0 = llvm.fpext %arg0 : !llvm.half to !llvm.float
  %1 = llvm.mlir.cast %0 : !llvm.float to !fir.real<4>
  llvm.call @foop(%1) : (!fir.real<4>) -> ()
  llvm.return
}

This patch disable the introduction of the llvm.mlir.cast and preserve the previous behavior.

Also fixes https://github.com/llvm/llvm-project/issues/55210.

Note: This is part of upstreaming from the fir-dev branch of
https://github.com/flang-compiler/f18-llvm-project.

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

Diff Detail

Event Timeline

Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 7 2022, 6:12 AM
kiranchandramohan requested review of this revision.Jun 7 2022, 6:12 AM
kiranchandramohan edited the summary of this revision. (Show Details)Jun 7 2022, 6:18 AM

This was added as a workaround on fir-dev (marked as FIXME), but we haven't identified a better approach just yet and we need this in order to progress with upstreaming (and to resolve #55210).

Makes sense to me, thanks for sending!

awarzynski accepted this revision.Jun 8 2022, 6:44 AM
This revision is now accepted and ready to land.Jun 8 2022, 6:44 AM

This was added as a workaround on fir-dev (marked as FIXME), but we haven't identified a better approach just yet and we need this in order to progress with upstreaming (and to resolve #55210).

Makes sense to me, thanks for sending!

I'm curious about other approach you tried here. Do you mind to share?

This was added as a workaround on fir-dev (marked as FIXME), but we haven't identified a better approach just yet and we need this in order to progress with upstreaming (and to resolve #55210).

Makes sense to me, thanks for sending!

I'm curious about other approach you tried here. Do you mind to share?

Jean's original patch (https://github.com/flang-compiler/f18-llvm-project/pull/313) called it a workaround hence I called it a temporary fix in this patch.
We have not tried anything else. There was a bit of discussion in https://github.com/llvm/llvm-project/issues/55210 about some context-sensitive lowering of fir.box. We prioritised upstreaming over attempting to fix.

Jean's original patch (https://github.com/flang-compiler/f18-llvm-project/pull/313) called it a workaround hence I called it a temporary fix in this patch.
We have not tried anything else. There was a bit of discussion in https://github.com/llvm/llvm-project/issues/55210 about some context-sensitive lowering of fir.box. We prioritised upstreaming over attempting to fix.

Ok, @awarzynski comment made it sound like there was some investigations done on this. Would be good to check with MLIR folks how we can avoid this workaround.

Ok, @awarzynski comment made it sound like there was some investigations done on this.

Oh, I was just referring to the discussion on GitHub.

Would be good to check with MLIR folks how we can avoid this workaround.

+1