Optimization of complex number division

Validating the accuracy and speed is difficult, and I don’t think we can yet determine which algorithms should be adopted at each optimization level. Therefore, how about implementing only the -fcomplex-arithmetic=[full|improved|basic] option first? Following Clang’s behavior, I plan to implement it with the following behavior:

  • Implement -complex-range=XXX in the Flang frontend:
    • full: use a runtime function (default, same behavior as current)
    • improved: lower to complex.div and use Smith’s algorithm
    • basic: lower to complex.div and use algebraic algorithm
  • Implement -fcomplex-arithmetic=XXX in the Flang driver:
    • full, improved, basic: pass the corresponding value to -complex-range=XXX

Regarding the implementation, I plan to use LoweringOptions to determine whether to use runtime calls or lowering to MLIR, and use CodeGenOptions to set a pass option that specifies the algorithm. If we want to specify complex number calculations with other optimization levels or options in the future, we should be able to modify the driver to pass the value to -complex-range=.