[llvm-commits] [llvm] r170226 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp test/Transforms/InstCombine/fast-math.ll

Shuxin Yang shuxin.llvm at gmail.com
Mon Dec 17 16:51:21 PST 2012


In order to optimize that way, I need to create instruction "I = X * A" 
first. (Maybe I need to create a dummy instruction
to use this instruction as well), then go ahead call SimplifyFMul(). 
Often time, if fails, I have to toss away the instruction
I just created.

Once in a while, It might prevail. However, the chance to optimize away 
both X * A and X * B is quite slim.
I don't think it worth this trouble.

That said, I would consider the xform your proposed when I try to 
optimize mpy in a more aggressive way (I'm working on it).

BTW, I don't think "X * cond ? 1.0 : 0.0" is quite rare. I see such expr 
in many Fortran programs.


On 12/17/12 3:34 PM, Michael Ilseman wrote:
> On Dec 17, 2012, at 9:51 AM, Shuxin Yang <shuxin.llvm at gmail.com> wrote:
>
>> Your proposed transformation:
>>      X op (select cond A, B) -> select cond (X op A), (X op B)
>> could improve performance iff  *BOTH* "X op A" and "X op B" don't need extra instructions to evaluate their value.
>>
> Note that "not needing extra instructions" is exactly the way the SimplifyInstruction APIs are set up (e.g. SimplifyFMul). If they return non-0, then the expression has been reduced. You might be able to both clean up your code and generalize it a little bit this way.
>
> See if the following works or is reasonable:
>
>> if (A = SimplifyFMul(SLHS, X, …)) && (B = SimplifyFMul(SRHS, X, …)) {
>    … create a new select between A and B …
> }
>
>
>> Other than the "cond ? 1 : 0" expression,  It is hard to imagine real-world applications have such opportunities.
>>
>
>
>> On 12/16/12 8:49 AM, Duncan Sands wrote:
>>> Hi Shuxin,
>>>
>>> On 14/12/12 19:46, Shuxin Yang wrote:
>>>> Author: shuxin_yang
>>>> Date: Fri Dec 14 12:46:06 2012
>>>> New Revision: 170226
>>>>
>>>> URL: http://llvm.org/viewvc/llvm-project?rev=170226&view=rev
>>>> Log:
>>>> rdar://12753946
>>>>
>>>> Implement rule : "x * (select cond 1.0, 0.0) -> select cond x, 0.0"
>>> this is a special case of:
>>>
>>>   X op (select cond A, B) -> select cond (X op A), (X op B)
>>>
>>> when X op A and X op B simplify (for example because passing X op A and
>>> X op B to InstructionSimplify say that they simplify).  Any chance of
>>> implementing this more general transform instead?
>>>
>>> Thanks, Duncan.
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list