This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH - [RFC] regrouping of expression tree for single multiply add.



Some architectures, such as PowerPC have floating multiply-add instructions
which may benefit certain applications. For example, our test has shown
full utilization of this instruction benefits 183.equake of the SPEC benchmark.
But to gain its full potential, I have to rearrange the expression tree in fold(...)
routine, as shown in the attached patch.


I would like to know if this is an appropriate place for this kind of optimization,
which may not necessarily benefit all architectures. Routine fold(...) seems to
be used for similar transformations extensively.


- Thanks, Fariborz Jahanian (fjahanian@apple.com)

Test Case:

double bad(int i, double b, double c, double d, double e, double **w) {
        return w[i][0] += b*c + d*e;
}

Before the patch (gcc -S -O2 -ffast-math)

...
        lwz r2,60(r1)
        fmul f4,f3,f4
        slwi r3,r3,2
        lwzx r9,r3,r2
        fmadd f2,f1,f2,f4
        lfd f1,0(r9)
        fadd f1,f1,f2
...

After the patch:

...
        fmadd f4,f3,f4,f0
        fmadd f2,f1,f2,f4
...

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.213.2.80
diff -c -p -r1.213.2.80 fold-const.c
*** fold-const.c 8 Mar 2004 18:05:40 -0000 1.213.2.80
--- fold-const.c 20 Mar 2004 19:40:21 -0000
*************** fold (tree expr)
*** 6063,6068 ****
--- 6063,6099 ----
TREE_OPERAND (arg0, 0),
build_real (type, c1)));
}
+ /* Convert a + (b + (c*d)) into (a + (c*d)) + b */
+ if (flag_unsafe_math_optimizations
+ && FLOAT_TYPE_P (type)
+ && !TREE_SIDE_EFFECTS(arg0)
+ && TREE_CODE (arg1) == PLUS_EXPR
+ && !TREE_SIDE_EFFECTS(arg1))
+ {
+ tree tree11;
+ tree11 = TREE_OPERAND (arg1, 1);
+ if (TREE_CODE (tree11) == MULT_EXPR)
+ {
+ tree tree0;
+ tree0 = fold (build (PLUS_EXPR, type, arg0, tree11));
+ return fold (build (PLUS_EXPR, type, tree0, TREE_OPERAND (arg1, 0)));
+ }
+ }
+ else if (flag_unsafe_math_optimizations
+ && FLOAT_TYPE_P (type)
+ && DECL_P(arg1)
+ && TREE_CODE (arg0) == PLUS_EXPR
+ && !TREE_SIDE_EFFECTS(arg0))
+ {
+ tree tree01;
+ tree01 = TREE_OPERAND (arg0, 1);
+ if (TREE_CODE (tree01) == MULT_EXPR)
+ {
+ tree tree0;
+ tree0 = fold (build (PLUS_EXPR, type, arg1, tree01));
+ return fold (build (PLUS_EXPR, type, tree0, TREE_OPERAND (arg0, 0)));
+ }
+ }
}


bit_rotate:




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]