Skip to content

Commit 9528edd

Browse files
committed
Skip running on AMDGCN through pass pipelines.
Propagate fast-math attributes, update tests.
1 parent c8715a1 commit 9528edd

File tree

6 files changed

+26
-22
lines changed

6 files changed

+26
-22
lines changed

flang/include/flang/Tools/CrossToolHelpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks {
134134
bool NSWOnLoopVarInc = true; ///< Add nsw flag to loop variable increments.
135135
bool EnableOpenMP = false; ///< Enable OpenMP lowering.
136136
bool EnableOpenMPSimd = false; ///< Enable OpenMP simd-only mode.
137+
bool SkipConvertComplexPow = false; ///< Do not run complex pow conversion.
137138
std::string InstrumentFunctionEntry =
138139
""; ///< Name of the instrument-function that is called on each
139140
///< function-entry

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ void CodeGenAction::generateLLVMIR() {
720720
const CodeGenOptions &opts = invoc.getCodeGenOpts();
721721
const auto &mathOpts = invoc.getLoweringOpts().getMathOptions();
722722
llvm::OptimizationLevel level = mapToLevel(opts);
723+
const llvm::TargetMachine &targetMachine = ci.getTargetMachine();
723724
mlir::DefaultTimingManager &timingMgr = ci.getTimingManager();
724725
mlir::TimingScope &timingScopeRoot = ci.getTimingScopeRoot();
725726

@@ -738,6 +739,7 @@ void CodeGenAction::generateLLVMIR() {
738739
pm.enableVerifier(/*verifyPasses=*/true);
739740

740741
MLIRToLLVMPassPipelineConfig config(level, opts, mathOpts);
742+
config.SkipConvertComplexPow = targetMachine.getTargetTriple().isAMDGCN();
741743
fir::registerDefaultInlinerPass(config);
742744

743745
if (auto vsr = getVScaleRange(ci)) {

flang/lib/Optimizer/Passes/Pipelines.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ void createDefaultFIROptimizerPassPipeline(mlir::PassManager &pm,
225225

226226
pm.addPass(mlir::createCanonicalizerPass(config));
227227
pm.addPass(fir::createSimplifyRegionLite());
228-
pm.addPass(fir::createConvertComplexPow());
228+
if (!pc.SkipConvertComplexPow)
229+
pm.addPass(fir::createConvertComplexPow());
229230
pm.addPass(mlir::createCSEPass());
230231

231232
if (pc.OptLevel.isOptimizingForSpeed())

flang/lib/Optimizer/Transforms/ConvertComplexPow.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ static bool isZero(Value v) {
5656

5757
void ConvertComplexPowPass::runOnOperation() {
5858
ModuleOp mod = getOperation();
59-
if (fir::getTargetTriple(mod).isAMDGCN())
60-
return;
61-
6259
fir::FirOpBuilder builder(mod, fir::getKindMapping(mod));
6360

6461
mod.walk([&](complex::PowOp op) {
@@ -118,6 +115,8 @@ void ConvertComplexPowPass::runOnOperation() {
118115
}
119116

120117
auto call = fir::CallOp::create(builder, loc, callee, args);
118+
if (auto fmf = op.getFastmathAttr())
119+
call.setFastmathAttr(fmf);
121120
op.replaceAllUsesWith(call.getResult(0));
122121
op.erase();
123122
});

flang/test/Transforms/convert-complex-pow.fir

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,98 +5,98 @@ module {
55
%c0 = arith.constant 0.000000e+00 : f32
66
%c1 = fir.convert %arg1 : (i32) -> f32
77
%c2 = complex.create %c1, %c0 : complex<f32>
8-
%0 = complex.pow %arg0, %c2 : complex<f32>
8+
%0 = complex.pow %arg0, %c2 {fastmath = #arith.fastmath<reassoc, contract, nsz>} : complex<f32>
99
return %0 : complex<f32>
1010
}
1111

1212
func.func @pow_c4_i8(%arg0: complex<f32>, %arg1: i64) -> complex<f32> {
1313
%c0 = arith.constant 0.000000e+00 : f32
1414
%c1 = fir.convert %arg1 : (i64) -> f32
1515
%c2 = complex.create %c1, %c0 : complex<f32>
16-
%0 = complex.pow %arg0, %c2 : complex<f32>
16+
%0 = complex.pow %arg0, %c2 {fastmath = #arith.fastmath<reassoc, contract, nsz>} : complex<f32>
1717
return %0 : complex<f32>
1818
}
1919

2020
func.func @pow_c4_c4(%arg0: complex<f32>, %arg1: complex<f32>) -> complex<f32> {
21-
%0 = complex.pow %arg0, %arg1 : complex<f32>
21+
%0 = complex.pow %arg0, %arg1 {fastmath = #arith.fastmath<reassoc, contract, nsz>} : complex<f32>
2222
return %0 : complex<f32>
2323
}
2424

2525
func.func @pow_c8_i4(%arg0: complex<f64>, %arg1: i32) -> complex<f64> {
2626
%c0 = arith.constant 0.000000e+00 : f64
2727
%c1 = fir.convert %arg1 : (i32) -> f64
2828
%c2 = complex.create %c1, %c0 : complex<f64>
29-
%0 = complex.pow %arg0, %c2 : complex<f64>
29+
%0 = complex.pow %arg0, %c2 {fastmath = #arith.fastmath<reassoc, contract, nsz>} : complex<f64>
3030
return %0 : complex<f64>
3131
}
3232

3333
func.func @pow_c8_i8(%arg0: complex<f64>, %arg1: i64) -> complex<f64> {
3434
%c0 = arith.constant 0.000000e+00 : f64
3535
%c1 = fir.convert %arg1 : (i64) -> f64
3636
%c2 = complex.create %c1, %c0 : complex<f64>
37-
%0 = complex.pow %arg0, %c2 : complex<f64>
37+
%0 = complex.pow %arg0, %c2 {fastmath = #arith.fastmath<reassoc, contract, nsz>} : complex<f64>
3838
return %0 : complex<f64>
3939
}
4040

4141
func.func @pow_c8_c8(%arg0: complex<f64>, %arg1: complex<f64>) -> complex<f64> {
42-
%0 = complex.pow %arg0, %arg1 : complex<f64>
42+
%0 = complex.pow %arg0, %arg1 {fastmath = #arith.fastmath<reassoc, contract, nsz>} : complex<f64>
4343
return %0 : complex<f64>
4444
}
4545

4646
func.func @pow_c16_i4(%arg0: complex<f128>, %arg1: i32) -> complex<f128> {
4747
%c0 = arith.constant 0.000000e+00 : f128
4848
%c1 = fir.convert %arg1 : (i32) -> f128
4949
%c2 = complex.create %c1, %c0 : complex<f128>
50-
%0 = complex.pow %arg0, %c2 : complex<f128>
50+
%0 = complex.pow %arg0, %c2 {fastmath = #arith.fastmath<reassoc, contract, nsz>} : complex<f128>
5151
return %0 : complex<f128>
5252
}
5353

5454
func.func @pow_c16_i8(%arg0: complex<f128>, %arg1: i64) -> complex<f128> {
5555
%c0 = arith.constant 0.000000e+00 : f128
5656
%c1 = fir.convert %arg1 : (i64) -> f128
5757
%c2 = complex.create %c1, %c0 : complex<f128>
58-
%0 = complex.pow %arg0, %c2 : complex<f128>
58+
%0 = complex.pow %arg0, %c2 {fastmath = #arith.fastmath<reassoc, contract, nsz>} : complex<f128>
5959
return %0 : complex<f128>
6060
}
6161

6262
func.func @pow_c16_c16(%arg0: complex<f128>, %arg1: complex<f128>) -> complex<f128> {
63-
%0 = complex.pow %arg0, %arg1 : complex<f128>
63+
%0 = complex.pow %arg0, %arg1 {fastmath = #arith.fastmath<reassoc, contract, nsz>} : complex<f128>
6464
return %0 : complex<f128>
6565
}
6666
}
6767

6868
// CHECK-LABEL: func.func @pow_c4_i4(
69-
// CHECK: fir.call @_FortranAcpowi(%{{.*}}, %{{.*}}) : (complex<f32>, i32) -> complex<f32>
69+
// CHECK: fir.call @_FortranAcpowi(%{{.*}}, %{{.*}}) fastmath<reassoc,nsz,contract> : (complex<f32>, i32) -> complex<f32>
7070
// CHECK-NOT: complex.pow
7171

7272
// CHECK-LABEL: func.func @pow_c4_i8(
73-
// CHECK: fir.call @_FortranAcpowk(%{{.*}}, %{{.*}}) : (complex<f32>, i64) -> complex<f32>
73+
// CHECK: fir.call @_FortranAcpowk(%{{.*}}, %{{.*}}) fastmath<reassoc,nsz,contract> : (complex<f32>, i64) -> complex<f32>
7474
// CHECK-NOT: complex.pow
7575

7676
// CHECK-LABEL: func.func @pow_c4_c4(
77-
// CHECK: fir.call @cpowf(%{{.*}}, %{{.*}}) : (complex<f32>, complex<f32>) -> complex<f32>
77+
// CHECK: fir.call @cpowf(%{{.*}}, %{{.*}}) fastmath<reassoc,nsz,contract> : (complex<f32>, complex<f32>) -> complex<f32>
7878
// CHECK-NOT: complex.pow
7979

8080
// CHECK-LABEL: func.func @pow_c8_i4(
81-
// CHECK: fir.call @_FortranAzpowi(%{{.*}}, %{{.*}}) : (complex<f64>, i32) -> complex<f64>
81+
// CHECK: fir.call @_FortranAzpowi(%{{.*}}, %{{.*}}) fastmath<reassoc,nsz,contract> : (complex<f64>, i32) -> complex<f64>
8282
// CHECK-NOT: complex.pow
8383

8484
// CHECK-LABEL: func.func @pow_c8_i8(
85-
// CHECK: fir.call @_FortranAzpowk(%{{.*}}, %{{.*}}) : (complex<f64>, i64) -> complex<f64>
85+
// CHECK: fir.call @_FortranAzpowk(%{{.*}}, %{{.*}}) fastmath<reassoc,nsz,contract> : (complex<f64>, i64) -> complex<f64>
8686
// CHECK-NOT: complex.pow
8787

8888
// CHECK-LABEL: func.func @pow_c8_c8(
89-
// CHECK: fir.call @cpow(%{{.*}}, %{{.*}}) : (complex<f64>, complex<f64>) -> complex<f64>
89+
// CHECK: fir.call @cpow(%{{.*}}, %{{.*}}) fastmath<reassoc,nsz,contract> : (complex<f64>, complex<f64>) -> complex<f64>
9090
// CHECK-NOT: complex.pow
9191

9292
// CHECK-LABEL: func.func @pow_c16_i4(
93-
// CHECK: fir.call @_FortranAcqpowi(%{{.*}}, %{{.*}}) : (complex<f128>, i32) -> complex<f128>
93+
// CHECK: fir.call @_FortranAcqpowi(%{{.*}}, %{{.*}}) fastmath<reassoc,nsz,contract> : (complex<f128>, i32) -> complex<f128>
9494
// CHECK-NOT: complex.pow
9595

9696
// CHECK-LABEL: func.func @pow_c16_i8(
97-
// CHECK: fir.call @_FortranAcqpowk(%{{.*}}, %{{.*}}) : (complex<f128>, i64) -> complex<f128>
97+
// CHECK: fir.call @_FortranAcqpowk(%{{.*}}, %{{.*}}) fastmath<reassoc,nsz,contract> : (complex<f128>, i64) -> complex<f128>
9898
// CHECK-NOT: complex.pow
9999

100100
// CHECK-LABEL: func.func @pow_c16_c16(
101-
// CHECK: fir.call @_FortranACPowF128(%{{.*}}, %{{.*}}) : (complex<f128>, complex<f128>) -> complex<f128>
101+
// CHECK: fir.call @_FortranACPowF128(%{{.*}}, %{{.*}}) fastmath<reassoc,nsz,contract> : (complex<f128>, complex<f128>) -> complex<f128>
102102
// CHECK-NOT: complex.pow

flang/tools/bbc/bbc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ static llvm::LogicalResult convertFortranSourceToMLIR(
538538

539539
// Add O2 optimizer pass pipeline.
540540
MLIRToLLVMPassPipelineConfig config(llvm::OptimizationLevel::O2);
541+
config.SkipConvertComplexPow = targetMachine.getTargetTriple().isAMDGCN();
541542
if (enableOpenMP)
542543
config.EnableOpenMP = true;
543544
config.NSWOnLoopVarInc = !integerWrapAround;

0 commit comments

Comments
 (0)