arunmoezhi
arunmoezhi

Reputation: 3200

Expression optimization

I have an expression involving REAL as:

xf=w1*x1 + w2*x2 + w3*x3 + w1*y1 + w2*y2 + w3*y3

I want to know if the (Intel Fortran) compiler optimized it to:

xf=w1*(x1+y1) + w2*(x2+y2) + w3*(x3+y3)

How do I see the expression tree which was generated for this expression?

Upvotes: 0

Views: 296

Answers (2)

Hot Licks
Hot Licks

Reputation: 47749

Your standard common subexpression schemes would not perform the above transformation, and some languages would regard the transformation as illegal, since it could result in different side-effects.

But high-performance FORTRAN compilers (which probably excludes Intel FORTRAN) might do it.

Upvotes: 1

sepp2k
sepp2k

Reputation: 370415

How do I see the expression tree which was generated for this expression?

If your compiler has an option to display the tree after a given optimization phase, you can use that option. To find out whether that's the case, consult your compiler's optimization.

If your compiler does not have such an option, you won't be able to see which trees (or other internal representations) the compiler generated during its run. In that case your best bet would be to simply look at the generated assembly to see which arithmetic operations will be performed.

Upvotes: 0

Related Questions