[llvm] [SimplifyLibCalls] Merge sqrt into the power of exp (PR #79146)
Anton Sidorenko via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 5 02:58:40 PST 2024
================
@@ -88,7 +88,114 @@ define float @sqrt_call_fabs_f32(float %x) {
ret float %sqrt
}
+define double @sqrt_exp(double %x) {
+; CHECK-LABEL: @sqrt_exp(
+; CHECK-NEXT: [[MERGED_SQRT:%.*]] = fmul fast double [[X:%.*]], 5.000000e+00
+; CHECK-NEXT: [[E:%.*]] = call fast double @llvm.exp.f64(double [[MERGED_SQRT]])
+; CHECK-NEXT: ret double [[E]]
+;
+ %mul = fmul fast double %x, 10.0
+ %e = call fast double @llvm.exp.f64(double %mul)
+ %res = call fast double @llvm.sqrt.f64(double %e)
+ ret double %res
+}
+
+define double @sqrt_exp_2(double %x) {
+; CHECK-LABEL: @sqrt_exp_2(
+; CHECK-NEXT: [[MERGED_SQRT:%.*]] = fmul fast double [[X:%.*]], 5.000000e+00
+; CHECK-NEXT: [[E:%.*]] = call fast double @exp(double [[MERGED_SQRT]])
+; CHECK-NEXT: ret double [[E]]
+;
+ %mul = fmul fast double %x, 10.0
+ %e = call fast double @exp(double %mul)
+ %res = call fast double @sqrt(double %e)
+ ret double %res
+}
+
+define double @sqrt_exp2(double %x) {
+; CHECK-LABEL: @sqrt_exp2(
+; CHECK-NEXT: [[MERGED_SQRT:%.*]] = fmul fast double [[X:%.*]], 5.000000e+00
+; CHECK-NEXT: [[E:%.*]] = call fast double @exp2(double [[MERGED_SQRT]])
+; CHECK-NEXT: ret double [[E]]
+;
+ %mul = fmul fast double %x, 10.0
+ %e = call fast double @exp2(double %mul)
+ %res = call fast double @sqrt(double %e)
+ ret double %res
+}
+
+define double @sqrt_exp10(double %x) {
+; CHECK-LABEL: @sqrt_exp10(
+; CHECK-NEXT: [[MERGED_SQRT:%.*]] = fmul fast double [[X:%.*]], 5.000000e+00
+; CHECK-NEXT: [[E:%.*]] = call fast double @exp10(double [[MERGED_SQRT]])
+; CHECK-NEXT: ret double [[E]]
+;
+ %mul = fmul fast double %x, 10.0
+ %e = call fast double @exp10(double %mul)
+ %res = call fast double @sqrt(double %e)
+ ret double %res
+}
+
+define double @sqrt_exp_nofast_1(double %x) {
+; CHECK-LABEL: @sqrt_exp_nofast_1(
+; CHECK-NEXT: [[MERGED_SQRT:%.*]] = fmul fast double [[X:%.*]], 5.000000e+00
+; CHECK-NEXT: [[E:%.*]] = call fast double @llvm.exp.f64(double [[MERGED_SQRT]])
+; CHECK-NEXT: ret double [[E]]
+;
+ %mul = fmul double %x, 10.0
+ %e = call fast double @llvm.exp.f64(double %mul)
+ %res = call fast double @llvm.sqrt.f64(double %e)
+ ret double %res
+}
+
+; Negative test
+define double @sqrt_exp_nofast_2(double %x) {
+; CHECK-LABEL: @sqrt_exp_nofast_2(
+; CHECK-NEXT: [[MUL:%.*]] = fmul fast double [[X:%.*]], 1.000000e+01
+; CHECK-NEXT: [[E:%.*]] = call double @llvm.exp.f64(double [[MUL]])
+; CHECK-NEXT: [[RES:%.*]] = call fast double @llvm.sqrt.f64(double [[E]])
+; CHECK-NEXT: ret double [[RES]]
+;
+ %mul = fmul fast double %x, 10.0
+ %e = call double @llvm.exp.f64(double %mul)
+ %res = call fast double @llvm.sqrt.f64(double %e)
+ ret double %res
+}
+
+; Negative test
+define double @sqrt_exp_nofast_3(double %x) {
+; CHECK-LABEL: @sqrt_exp_nofast_3(
+; CHECK-NEXT: [[MUL:%.*]] = fmul fast double [[X:%.*]], 1.000000e+01
+; CHECK-NEXT: [[E:%.*]] = call fast double @llvm.exp.f64(double [[MUL]])
+; CHECK-NEXT: [[RES:%.*]] = call double @llvm.sqrt.f64(double [[E]])
+; CHECK-NEXT: ret double [[RES]]
+;
+ %mul = fmul fast double %x, 10.0
+ %e = call fast double @llvm.exp.f64(double %mul)
+ %res = call double @llvm.sqrt.f64(double %e)
+ ret double %res
+}
+
+; Negative test
+define double @sqrt_exp_noconst(double %x, double %y) {
+; CHECK-LABEL: @sqrt_exp_noconst(
+; CHECK-NEXT: [[MUL:%.*]] = fmul fast double [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[E:%.*]] = call fast double @llvm.exp.f64(double [[MUL]])
+; CHECK-NEXT: [[RES:%.*]] = call double @llvm.sqrt.f64(double [[E]])
+; CHECK-NEXT: ret double [[RES]]
+;
+ %mul = fmul fast double %x, %y
+ %e = call fast double @llvm.exp.f64(double %mul)
+ %res = call double @llvm.sqrt.f64(double %e)
+ ret double %res
+}
+
----------------
asi-sc wrote:
@jcranmer-intel, in your oppinion, what is the correct set of flags? Since you said that it is consistent with the existing practice, I won't change them in this PR. But we may start a discussion at discourse and systematically change all places.
https://github.com/llvm/llvm-project/pull/79146
More information about the llvm-commits
mailing list