[llvm-commits] [PATCH] Teach IRBuilder about simplifying BinOp(Value, Constant)

Nick Lewycky nicholas at mxc.ca
Sat Jan 3 08:45:03 PST 2009


Hey Edwin,

The one thing I encountered when playing around with IRBuilder isn't 
handled here: select constant, value, value. This comes up due to 
expressions like sizeof(ptr)==32 ? X : Y. The existing constant folder 
need all three operands to be constant.

Could you add that case?

Thanks,
Nick

Török Edwin wrote:
> On 2008-12-29 19:43, Török Edwin wrote:
>   
>> Will submit a new patch later.
>>   
>>     
>
> Here is the new patch, noteworthy changes:
> - simplifications implemented in ConstantFolder (default on)
> - except for the find-identical-instruction simplification, which is
> default off, configurable via template parameter
> - for binops there is now only CreateBinOp in constantfolder/nofolder
> - NoFolder now simply returns 0 for binops, and lets IRBuilder create
> the binary operator, and insert it
> (I wonder how it ever worked before, without inserting the instruction
> it created?)
> - TargetFolder is derived from ConstantFolder now, to reuse the
> simplifications
> - new variants of ConstantFoldInstruction/ConstantFoldInstOperands that
> do these simplifications also
> - it first tries to simplify, and if it fails then search for already
> existing instruction (if enabled)
> - try to comply more with LLVM coding style
>
> Some thoughts, if you agree I'll make these changes too
> - copy+paste in createadd/createsub, etc. is obvious, I could just make
> them call this->CreateBinOp, and let
> the compiler constant-propagate, and inline expand
> - I also attached instcombine-trivial.ll which confirms that instcombine
> does these optimizations, should I add it to test/Transforms/InstCombine?
>
> What do you think of my patch now?
>
> Best regards,
> --Edwin
>
>
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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