[flang-commits] [flang] [Flang] Extracting internal constants from scalar literals (PR #73829)

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Sat Jun 15 09:12:04 PDT 2024


https://github.com/kiranchandramohan approved this pull request.

We probably have to document this a bit better.

Something like the following for the Pattern.
```
If the Call Ops argument is an alloca with `getAdaptToByRefAttrName` attribute.
If this alloca is used by a single Store and the store dominates the callOp and the store writes a constant to the alloca.

Additionally, delete the store if and only if the store dominates two operations (ie itself and the CallOp).
```

In general, the pass here works due to a mix of some guarantees provided by lowering and some enforced by the pass. It would be good to clarify what is guaranteed by each.

I was initially concerned that it works for the following function (where modify_me modifies the alloca value and print_me just prints it). I imagine such a situation will not arise in practise due to the lowering guarantees. 
```
func.func @func(%arg0: !fir.ref<i32>, %arg1: i1) {
  %c2_i32 = arith.constant 2 : i32
  %addr1 = fir.alloca i32 {adapt.valuebyref}
  fir.store %c2_i32 to %addr1 : !fir.ref<i32>
  fir.call @modify_me(%addr1) : (!fir.ref<i32>) -> ()
  fir.call @print_me(%addr1) : (!fir.ref<i32>) -> ()
  return
}
```

Should we consider adding this pass earlier in the flow?

Please wait for @vzakhari and @tblah.

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


More information about the flang-commits mailing list