[flang-commits] [flang] cf550e6 - [flang] Run MathToLLVM conversion as part of math conversion PM.

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Tue Feb 21 19:16:10 PST 2023


Author: Slava Zakharin
Date: 2023-02-21T19:15:45-08:00
New Revision: cf550e6184dfeb1c2838132b4910548002d08563

URL: https://github.com/llvm/llvm-project/commit/cf550e6184dfeb1c2838132b4910548002d08563
DIFF: https://github.com/llvm/llvm-project/commit/cf550e6184dfeb1c2838132b4910548002d08563.diff

LOG: [flang] Run MathToLLVM conversion as part of math conversion PM.

We used to specify benefit=0 for MathToLibm patterns so that
MathToLLVM patterns are more preferable. D144450 removed
the benefit parameter, so we have to run MathToLLVM separately now.

This resolves Intrinsics/math-codegen failure caused by D144450.

Differential Revision: https://reviews.llvm.org/D144523

Added: 
    

Modified: 
    flang/lib/Optimizer/CodeGen/CodeGen.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 4ac5451cc7cf0..3816d9b7caf51 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -3772,6 +3772,11 @@ class FIRToLLVMLowering
     mathConvertionPM.addPass(
         mlir::createConvertMathToFuncs(mathToFuncsOptions));
     mathConvertionPM.addPass(mlir::createConvertComplexToStandardPass());
+    // Convert Math dialect operations into LLVM dialect operations.
+    // There is no way to prefer MathToLLVM patterns over MathToLibm
+    // patterns (applied below), so we have to run MathToLLVM conversion here.
+    mathConvertionPM.addNestedPass<mlir::func::FuncOp>(
+        mlir::createConvertMathToLLVMPass());
     if (mlir::failed(runPipeline(mathConvertionPM, mod)))
       return signalPassFailure();
 
@@ -3826,9 +3831,8 @@ class FIRToLLVMLowering
     mlir::arith::populateArithToLLVMConversionPatterns(typeConverter, pattern);
     mlir::cf::populateControlFlowToLLVMConversionPatterns(typeConverter,
                                                           pattern);
-    // Convert math-like dialect operations, which can be produced
-    // when late math lowering mode is used, into llvm dialect.
-    mlir::populateMathToLLVMConversionPatterns(typeConverter, pattern);
+    // Math operations that have not been converted yet must be converted
+    // to Libm.
     mlir::populateMathToLibmConversionPatterns(pattern);
     mlir::populateComplexToLLVMConversionPatterns(typeConverter, pattern);
     mlir::ConversionTarget target{*context};


        


More information about the flang-commits mailing list