[llvm-commits] [PATCH] Teach IRBuilder about simplifying BinOp(Value, Constant)
To"ro"k Edwin
edwintorok at gmail.com
Mon Dec 29 04:50:44 PST 2008
On 2008-12-29 14:34, Duncan Sands wrote:
> Hi Edwin,
>
>
>> We now have a NoopFolder, ConstantFolder, and TargetFolder.
>>
>> Should the simplifications be part of ConstantFolder, or should there be
>> a 4th "folder" like this:
>> NoopFolder, ConstantFolder, SimplifyingConstantFolder (derived from
>> ConstantFolder), TargetFolder (derived from SimplifyingConstantFolder)?
>>
>
> I think it should be part of ConstantFolder. Of course, TargetFolder
> should do at least as much as ConstantFolder.
>
Ok.
>
>> Yes, that looks like a good place. Can I then just make ConstantFolder
>> use ConstantFoldInstruction?
>>
>
> It's probably more efficient to directly call ConstantExpr::get if all
> operands are constants rather than building an instruction only to have
> ConstantFoldInstruction maybe throw it away in favour of a ConstantExpr.
>
Agreed, I don't want to create an instruction just to throw it away later.
I thought to have a new variant of ConstantFoldInstOperands that takes a
Value** instead of a Constant**. Then ConstantFolder could call that
without actually creating the instruction, and if both are constants,
it would return ConstantExpr::get. However there is still the issue that
the new ConstantFoldInstOperands won't be inlined, whereas previously
the ConstantExpr::get were inline.
So how about calling the ConstantExpr::get through the folder (as now),
and also add a call to Folder.simplify, something like:
Value *CreateAnd(Value *LHS, Value *RHS, const char *Name = "") {
Constant *LC = dyn_cast<Constant>(LHS);
Constant *RC = dyn_cast<Constant>(RHS);
if (LC && RC)
return Folder.CreateAnd(LC, RC);
if (LC || RC)
if (Value *S = Folder.SimplifyBinOp(Instruction::And, LHS, RHS,
LC, RC, InsertPt))
return S;
return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name);
}
ConstantFoldInstruction (and a variant of ConstantFoldInstOperands) will
also use this Folder.
Best regards,
--Edwin
More information about the llvm-commits
mailing list