On Thu, Jun 28, 2018 at 07:41:30AM -0700, Steve Kargl wrote: > I am opposed to the change of TRUTH_AND_EXPR to TRUTH_ANDIF_EXPR, > where you are special casing logical expressions that involve > .and. and .or.
I think using TRUTH_AND_EXPR is the right thing to do, and if fortran functions can be optimized away if their results aren't used, then let's add some new attribute like const or pure attributes that would allow the middle-end to optimize away calls to functions with that attribute if the lhs isn't needed. This attribute has been discussed recently in the thread about caching functions. The question is what exactly should this attribute allow, if just DCE if lhs is unused, or also CSE, if the function has been called with the same arguments earlier, if it can be optimized into copying the result of the earlier call. > In fact, I'll be submitting a bug report for a missed optimization. > > subroutine foo(x,y) subroutine foo(x,y) > real x(10), y(10) real x(10), y(10) > y = 0*sin(x) y = 0 > end subroutine foo end subroutine foo > > .L2: pxor %xmm0, %xmm0 > call sinf movq $0, 32(%rsi) > pxor %xmm1, %xmm1 movups %xmm0, (%rsi) > mulss %xmm1, %xmm0 movups %xmm0, 16(%rsi) > movss %xmm0, 0(%rbp,%rbx) > addq $4, %rbx > cmpq $40, %rbx > jne .L2 > > which I'm sure you'll just be thrilled with. For floating point, you generally need -ffast-math to be able to optimize such computations away, sinf already has const attribute (at least in C/C++), so with -ffast-math it is optimized. Jakub