[flang-commits] [flang] [flang] Use fir.declare/fir.dummy_scope for TBAA tags attachments. (PR #92472)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Thu May 23 02:26:35 PDT 2024


================
@@ -30,8 +30,15 @@ using namespace mlir;
 
 static bool isDummyArgument(mlir::Value v) {
   auto blockArg{mlir::dyn_cast<mlir::BlockArgument>(v)};
-  if (!blockArg)
+  if (!blockArg) {
+    auto defOp = v.getDefiningOp();
+    if (defOp) {
+      if (auto declareOp = mlir::dyn_cast<fir::DeclareOp>(defOp))
+        if (declareOp.getDummyScope())
+          return true;
----------------
tblah wrote:

Slightly modifying the sample from the test so that `%arg0` is now a local allocation:
```
func.func @test1(%arg1: !fir.ref<f32> {fir.bindc_name = "y", fir.target}) {
  %alloca = fir.alloca i32
  %scope_out = fir.dummy_scope : !fir.dscope
  %0 = fir.declare %alloca {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFtestEx"} : (!fir.ref<f32>, !fir.dscope) -> !fir.ref<f32>
  %1 = fir.declare %arg1 dummy_scope %scope_out {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFtestEy"} : (!fir.ref<f32>, !fir.dscope) -> !fir.ref<f32>
  %2 = fir.load %1 : !fir.ref<f32>
  fir.store %2 to %0 : !fir.ref<f32>
  %scope_in1 = fir.dummy_scope : !fir.dscope
  %3 = fir.declare %0 dummy_scope %scope_in1 {uniq_name = "_QFtestFinnerEx"} : (!fir.ref<f32>, !fir.dscope) -> !fir.ref<f32>
  %4 = fir.declare %1 dummy_scope %scope_in1 {uniq_name = "_QFtestFinnerEy"} : (!fir.ref<f32>, !fir.dscope) -> !fir.ref<f32>
  %5 = fir.load %4 : !fir.ref<f32>
  fir.store %5 to %3 : !fir.ref<f32>
  %scope_in2 = fir.dummy_scope : !fir.dscope
  %6 = fir.declare %0 dummy_scope %scope_in2 {uniq_name = "_QFtestFinnerEx"} : (!fir.ref<f32>, !fir.dscope) -> !fir.ref<f32>
  %7 = fir.declare %1 dummy_scope %scope_in2 {uniq_name = "_QFtestFinnerEy"} : (!fir.ref<f32>, !fir.dscope) -> !fir.ref<f32>
  %8 = fir.load %7 : !fir.ref<f32>
  fir.store %8 to %6 : !fir.ref<f32>
  return
}
```

`%3` and `%0` should alias. But I think the current logic will determine that `%3` is a dummy argument due to its alias scope. Dummy arguments do not alias with local allocations and so we would incorrectly assume that they do not alias.

https://github.com/llvm/llvm-project/pull/92472


More information about the flang-commits mailing list