[codeGen] Added math.exp2 expansion. (#13124)
IREE Compiler was failing because math.exp2 implementation is not
available in the back end. This patch will call the MLIR function to
expand exp2(a) to exp(ln(2) *a).
Fixes #12974
diff --git a/compiler/src/iree/compiler/Codegen/Common/PolynomialApproximationPass.cpp b/compiler/src/iree/compiler/Codegen/Common/PolynomialApproximationPass.cpp
index 076793d..1f3294f 100644
--- a/compiler/src/iree/compiler/Codegen/Common/PolynomialApproximationPass.cpp
+++ b/compiler/src/iree/compiler/Codegen/Common/PolynomialApproximationPass.cpp
@@ -29,6 +29,7 @@
void runOnOperation() override {
RewritePatternSet mathPatterns(&getContext());
populateExpandTanPattern(mathPatterns);
+ populateExpandExp2FPattern(mathPatterns);
if (clNativeMathPrecision) {
mathPatterns.add<math::ErfPolynomialApproximation>(&getContext());
diff --git a/tests/e2e/regression/libm_linking.mlir b/tests/e2e/regression/libm_linking.mlir
index 353663a..d0b4afe 100644
--- a/tests/e2e/regression/libm_linking.mlir
+++ b/tests/e2e/regression/libm_linking.mlir
@@ -39,3 +39,11 @@
%result = math.floor %input : tensor<f32>
return %result : tensor<f32>
}
+
+// CHECK: vm.func private @exp2
+func.func @exp2(%input : tensor<f32>) -> (tensor<f32>) {
+ // May lower to llvm.intr.exp2 (exp2f)
+ %result = math.exp2 %input : tensor<f32>
+ return %result : tensor<f32>
+}
+