From a589ee134eb76fefc0b86bd8ee747764d2502b73 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Wed, 14 Nov 2007 11:12:31 +0000 Subject: [PATCH] - i_mapper_cbrt added - more test cases added [r16528] --- include/libfirm/lowering.h | 7 +++++ ir/be/test/rtsopt.c | 57 ++++++++++++++++++++++++++++++++++++- ir/lower/lower_intrinsics.c | 21 ++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/include/libfirm/lowering.h b/include/libfirm/lowering.h index 007bfc2fe..c2daa027d 100644 --- a/include/libfirm/lowering.h +++ b/include/libfirm/lowering.h @@ -292,6 +292,13 @@ int i_mapper_abs(ir_node *call, void *ctx); */ int i_mapper_sqrt(ir_node *call, void *ctx); +/** + * A mapper for the floating point cbrt(v): floattype sqrt(floattype v); + * + * @return 0 if the cbrt call was removed, 0 else. + */ +int i_mapper_cbrt(ir_node *call, void *ctx); + /** * A mapper for the floating point pow(a, b): floattype pow(floattype a, floattype b); * diff --git a/ir/be/test/rtsopt.c b/ir/be/test/rtsopt.c index 0d81e8394..fb1685a33 100644 --- a/ir/be/test/rtsopt.c +++ b/ir/be/test/rtsopt.c @@ -8,6 +8,11 @@ int test_abs(int a) { return abs(a); } +/* transform into Abs node, gcc(+), icc(+), cl(?) */ +long test_labs(long a) { + return labs(a); +} + /* transform into Abs node, gcc(+), icc(+), cl(+) */ double test_fabs(double a) { return fabs(a); @@ -164,11 +169,46 @@ double test_pow5(double a) { return pow(a, -1.0); } -/* evaluate cl(-) */ +/* evaluate into 1.0 gcc(+), icc(+), cl(-) */ double test_exp1(void) { return exp(0.0); } +/* evaluate into M_E gcc(+), icc(-), cl(?) */ +double test_exp2(void) { + return exp(1.0); +} + +/* evaluate gcc(-), icc(-), cl(?) */ +double test_exp3(void) { + return exp(7.3434); +} + +/* evaluate into 0.0 gcc(+), icc(-), cl(?) */ +double test_log1(void) { + return log(1.0); +} + +/* evaluate into 0.0 gcc(+), icc(-), cl(?) */ +double test_log2(void) { + return log2(1.0); +} + +/* evaluate into 0.0 gcc(+), icc(-), cl(?) */ +double test_log3(void) { + return log10(1.0); +} + +/* evaluate into 0.0 gcc(+), icc(-), cl(?) */ +double test_trunc1(void) { + return trunc(0.1); +} + +/* evaluate into 0.0 gcc(+), icc(-), cl(?) */ +double test_trunc2(void) { + return trunc(-8.9); +} + /* transform into putchar, gcc(+), icc(-), cl(-) */ void test_printf1() { printf("\n"); @@ -306,6 +346,21 @@ double test_sqrt3(void) { return sqrt(7.345); } +/* evaluate into 0.0, gcc(+), icc(-), cl(?) */ +double test_cbrt1(void) { + return cbrt(0.0); +} + +/* evaluate into 1.0, gcc(+), icc(-), cl(?) */ +double test_cbrt2(void) { + return cbrt(1.0); +} + +/* evaluate into -1.0, gcc(+), icc(-), cl(?) */ +double test_cbrt3(void) { + return cbrt(-1.0); +} + /* transform exit(3) into a return 3, gcc(-), icc(-), cl(-) */ int main() { printf("%f\n", test_asin1()); diff --git a/ir/lower/lower_intrinsics.c b/ir/lower/lower_intrinsics.c index 0d606bd81..30a19d8de 100644 --- a/ir/lower/lower_intrinsics.c +++ b/ir/lower/lower_intrinsics.c @@ -235,6 +235,27 @@ int i_mapper_sqrt(ir_node *call, void *ctx) { return 1; } +/* A mapper for the floating point cbrt. */ +int i_mapper_cbrt(ir_node *call, void *ctx) { + ir_node *mem; + tarval *tv; + ir_node *op = get_Call_param(call, 0); + (void) ctx; + + if (!is_Const(op)) + return 0; + + tv = get_Const_tarval(op); + if (! tarval_is_null(tv) && !tarval_is_one(tv) && !tarval_is_minus_one(tv)) + return 0; + + mem = get_Call_mem(call); + + /* cbrt(0) = 0, cbrt(1) = 1, cbrt(-1) = -1 */ + replace_call(op, call, mem, NULL, NULL); + return 1; +} + /* A mapper for the floating point pow. */ int i_mapper_pow(ir_node *call, void *ctx) { dbg_info *dbg; -- 2.20.1