<div dir="ltr"><div> The motivation is -O0 compile-time:<br><a href="https://reviews.llvm.org/rL86006">https://reviews.llvm.org/rL86006</a><br><br></div>...but it still seems bizarre to do logic folds in the builder. Is it possible that this isn't a problem anymore or that we can fix it somewhere else?<br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 22, 2018 at 10:45 AM, Craig Topper <span dir="ltr"><<a href="mailto:craig.topper@gmail.com" target="_blank">craig.topper@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Weirder still, the OR simplification works for vectors because it uses isNullValue on a Constant*. The AND simplification doesn't work for vectors because it checks for ConstantInt first. And both of them only work when the constant is on the RHS.</div><div class="gmail_extra"><span class="HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_-7203065262495319361gmail_signature" data-smartmail="gmail_signature">~Craig</div></div></font></span><div><div class="h5">
<br><div class="gmail_quote">On Thu, Feb 22, 2018 at 9:33 AM, Sanjay Patel via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: spatel<br>
Date: Thu Feb 22 09:33:20 2018<br>
New Revision: 325808<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=325808&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=325808&view=rev</a><br>
Log:<br>
[IRBuilder] add creators for FP with FMF; NFCI<br>
<br>
Also, add a helper for the constant folder to reduce duplication.<br>
<br>
It seems out-of-place for and/or to be doing simplifications here?<br>
Otherwise, I could have used the helper on those opcodes too.<br>
<br>
Modified:<br>
llvm/trunk/include/llvm/IR/IRB<wbr>uilder.h<br>
<br>
Modified: llvm/trunk/include/llvm/IR/IRB<wbr>uilder.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/IRBuilder.h?rev=325808&r1=325807&r2=325808&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/include/llvm/<wbr>IR/IRBuilder.h?rev=325808&r1=<wbr>325807&r2=325808&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/include/llvm/IR/IRB<wbr>uilder.h (original)<br>
+++ llvm/trunk/include/llvm/IR/IRB<wbr>uilder.h Thu Feb 22 09:33:20 2018<br>
@@ -917,17 +917,23 @@ private:<br>
return BO;<br>
}<br>
<br>
- Instruction *AddFPMathAttributes(Instructi<wbr>on *I,<br>
- MDNode *FPMathTag,<br>
- FastMathFlags FMF) const {<br>
- if (!FPMathTag)<br>
- FPMathTag = DefaultFPMathTag;<br>
- if (FPMathTag)<br>
- I->setMetadata(LLVMContext::MD<wbr>_fpmath, FPMathTag);<br>
+ Instruction *setFPAttrs(Instruction *I, MDNode *FPMD,<br>
+ FastMathFlags FMF) const {<br>
+ if (!FPMD)<br>
+ FPMD = DefaultFPMathTag;<br>
+ if (FPMD)<br>
+ I->setMetadata(LLVMContext::MD<wbr>_fpmath, FPMD);<br>
I->setFastMathFlags(FMF);<br>
return I;<br>
}<br>
<br>
+ Value *foldConstant(Instruction::Bin<wbr>aryOps Opc, Value *L,<br>
+ Value *R, const Twine &Name = nullptr) const {<br>
+ auto *LC = dyn_cast<Constant>(L);<br>
+ auto *RC = dyn_cast<Constant>(R);<br>
+ return (LC && RC) ? Insert(Folder.CreateBinOp(Opc, LC, RC), Name) : nullptr;<br>
+ }<br>
+<br>
public:<br>
Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "",<br>
bool HasNUW = false, bool HasNSW = false) {<br>
@@ -943,14 +949,6 @@ public:<br>
Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {<br>
return CreateAdd(LHS, RHS, Name, true, false);<br>
}<br>
- Value *CreateFAdd(Value *LHS, Value *RHS, const Twine &Name = "",<br>
- MDNode *FPMathTag = nullptr) {<br>
- if (Constant *LC = dyn_cast<Constant>(LHS))<br>
- if (Constant *RC = dyn_cast<Constant>(RHS))<br>
- return Insert(Folder.CreateFAdd(LC, RC), Name);<br>
- return Insert(AddFPMathAttributes(Bin<wbr>aryOperator::CreateFAdd(LHS, RHS),<br>
- FPMathTag, FMF), Name);<br>
- }<br>
Value *CreateSub(Value *LHS, Value *RHS, const Twine &Name = "",<br>
bool HasNUW = false, bool HasNSW = false) {<br>
if (Constant *LC = dyn_cast<Constant>(LHS))<br>
@@ -965,14 +963,6 @@ public:<br>
Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") {<br>
return CreateSub(LHS, RHS, Name, true, false);<br>
}<br>
- Value *CreateFSub(Value *LHS, Value *RHS, const Twine &Name = "",<br>
- MDNode *FPMathTag = nullptr) {<br>
- if (Constant *LC = dyn_cast<Constant>(LHS))<br>
- if (Constant *RC = dyn_cast<Constant>(RHS))<br>
- return Insert(Folder.CreateFSub(LC, RC), Name);<br>
- return Insert(AddFPMathAttributes(Bin<wbr>aryOperator::CreateFSub(LHS, RHS),<br>
- FPMathTag, FMF), Name);<br>
- }<br>
Value *CreateMul(Value *LHS, Value *RHS, const Twine &Name = "",<br>
bool HasNUW = false, bool HasNSW = false) {<br>
if (Constant *LC = dyn_cast<Constant>(LHS))<br>
@@ -987,14 +977,6 @@ public:<br>
Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") {<br>
return CreateMul(LHS, RHS, Name, true, false);<br>
}<br>
- Value *CreateFMul(Value *LHS, Value *RHS, const Twine &Name = "",<br>
- MDNode *FPMathTag = nullptr) {<br>
- if (Constant *LC = dyn_cast<Constant>(LHS))<br>
- if (Constant *RC = dyn_cast<Constant>(RHS))<br>
- return Insert(Folder.CreateFMul(LC, RC), Name);<br>
- return Insert(AddFPMathAttributes(Bin<wbr>aryOperator::CreateFMul(LHS, RHS),<br>
- FPMathTag, FMF), Name);<br>
- }<br>
Value *CreateUDiv(Value *LHS, Value *RHS, const Twine &Name = "",<br>
bool isExact = false) {<br>
if (Constant *LC = dyn_cast<Constant>(LHS))<br>
@@ -1019,35 +1001,14 @@ public:<br>
Value *CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name = "") {<br>
return CreateSDiv(LHS, RHS, Name, true);<br>
}<br>
- Value *CreateFDiv(Value *LHS, Value *RHS, const Twine &Name = "",<br>
- MDNode *FPMathTag = nullptr) {<br>
- if (Constant *LC = dyn_cast<Constant>(LHS))<br>
- if (Constant *RC = dyn_cast<Constant>(RHS))<br>
- return Insert(Folder.CreateFDiv(LC, RC), Name);<br>
- return Insert(AddFPMathAttributes(Bin<wbr>aryOperator::CreateFDiv(LHS, RHS),<br>
- FPMathTag, FMF), Name);<br>
- }<br>
Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") {<br>
- if (Constant *LC = dyn_cast<Constant>(LHS))<br>
- if (Constant *RC = dyn_cast<Constant>(RHS))<br>
- return Insert(Folder.CreateURem(LC, RC), Name);<br>
+ if (Value *V = foldConstant(Instruction::URem<wbr>, LHS, RHS, Name)) return V;<br>
return Insert(BinaryOperator::CreateU<wbr>Rem(LHS, RHS), Name);<br>
}<br>
Value *CreateSRem(Value *LHS, Value *RHS, const Twine &Name = "") {<br>
- if (Constant *LC = dyn_cast<Constant>(LHS))<br>
- if (Constant *RC = dyn_cast<Constant>(RHS))<br>
- return Insert(Folder.CreateSRem(LC, RC), Name);<br>
+ if (Value *V = foldConstant(Instruction::SRem<wbr>, LHS, RHS, Name)) return V;<br>
return Insert(BinaryOperator::CreateS<wbr>Rem(LHS, RHS), Name);<br>
}<br>
- Value *CreateFRem(Value *LHS, Value *RHS, const Twine &Name = "",<br>
- MDNode *FPMathTag = nullptr) {<br>
- if (Constant *LC = dyn_cast<Constant>(LHS))<br>
- if (Constant *RC = dyn_cast<Constant>(RHS))<br>
- return Insert(Folder.CreateFRem(LC, RC), Name);<br>
- return Insert(AddFPMathAttributes(Bin<wbr>aryOperator::CreateFRem(LHS, RHS),<br>
- FPMathTag, FMF), Name);<br>
- }<br>
-<br>
Value *CreateShl(Value *LHS, Value *RHS, const Twine &Name = "",<br>
bool HasNUW = false, bool HasNSW = false) {<br>
if (Constant *LC = dyn_cast<Constant>(LHS))<br>
@@ -1136,9 +1097,7 @@ public:<br>
}<br>
<br>
Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {<br>
- if (Constant *LC = dyn_cast<Constant>(LHS))<br>
- if (Constant *RC = dyn_cast<Constant>(RHS))<br>
- return Insert(Folder.CreateXor(LC, RC), Name);<br>
+ if (Value *V = foldConstant(Instruction::Xor, LHS, RHS, Name)) return V;<br>
return Insert(BinaryOperator::CreateX<wbr>or(LHS, RHS), Name);<br>
}<br>
Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") {<br>
@@ -1147,16 +1106,89 @@ public:<br>
Value *CreateXor(Value *LHS, uint64_t RHS, const Twine &Name = "") {<br>
return CreateXor(LHS, ConstantInt::get(LHS->getType(<wbr>), RHS), Name);<br>
}<br>
+ Value *CreateFAdd(Value *L, Value *R, const Twine &Name = "",<br>
+ MDNode *FPMD = nullptr) {<br>
+ if (Value *V = foldConstant(Instruction::FAdd<wbr>, L, R, Name)) return V;<br>
+ Instruction *I = setFPAttrs(BinaryOperator::Cre<wbr>ateFAdd(L, R), FPMD, FMF);<br>
+ return Insert(I, Name);<br>
+ }<br>
+ /// Copy fast-math-flags from an instruction rather than using the builder's<br>
+ /// default FMF.<br>
+ Value *CreateFAddFMF(Value *L, Value *R, Instruction *FMFSource,<br>
+ const Twine &Name = "") {<br>
+ if (Value *V = foldConstant(Instruction::FAdd<wbr>, L, R, Name)) return V;<br>
+ Instruction *I = setFPAttrs(BinaryOperator::Cre<wbr>ateFAdd(L, R), nullptr,<br>
+ FMFSource->getFastMathFlags())<wbr>;<br>
+ return Insert(I, Name);<br>
+ }<br>
+ Value *CreateFSub(Value *L, Value *R, const Twine &Name = "",<br>
+ MDNode *FPMD = nullptr) {<br>
+ if (Value *V = foldConstant(Instruction::FSub<wbr>, L, R, Name)) return V;<br>
+ Instruction *I = setFPAttrs(BinaryOperator::Cre<wbr>ateFSub(L, R), FPMD, FMF);<br>
+ return Insert(I, Name);<br>
+ }<br>
+ /// Copy fast-math-flags from an instruction rather than using the builder's<br>
+ /// default FMF.<br>
+ Value *CreateFSubFMF(Value *L, Value *R, Instruction *FMFSource,<br>
+ const Twine &Name = "") {<br>
+ if (Value *V = foldConstant(Instruction::FSub<wbr>, L, R, Name)) return V;<br>
+ Instruction *I = setFPAttrs(BinaryOperator::Cre<wbr>ateFSub(L, R), nullptr,<br>
+ FMFSource->getFastMathFlags())<wbr>;<br>
+ return Insert(I, Name);<br>
+ }<br>
+ Value *CreateFMul(Value *L, Value *R, const Twine &Name = "",<br>
+ MDNode *FPMD = nullptr) {<br>
+ if (Value *V = foldConstant(Instruction::FMul<wbr>, L, R, Name)) return V;<br>
+ Instruction *I = setFPAttrs(BinaryOperator::Cre<wbr>ateFMul(L, R), FPMD, FMF);<br>
+ return Insert(I, Name);<br>
+ }<br>
+ /// Copy fast-math-flags from an instruction rather than using the builder's<br>
+ /// default FMF.<br>
+ Value *CreateFMulFMF(Value *L, Value *R, Instruction *FMFSource,<br>
+ const Twine &Name = "") {<br>
+ if (Value *V = foldConstant(Instruction::FMul<wbr>, L, R, Name)) return V;<br>
+ Instruction *I = setFPAttrs(BinaryOperator::Cre<wbr>ateFMul(L, R), nullptr,<br>
+ FMFSource->getFastMathFlags())<wbr>;<br>
+ return Insert(I, Name);<br>
+ }<br>
+ Value *CreateFDiv(Value *L, Value *R, const Twine &Name = "",<br>
+ MDNode *FPMD = nullptr) {<br>
+ if (Value *V = foldConstant(Instruction::FDiv<wbr>, L, R, Name)) return V;<br>
+ Instruction *I = setFPAttrs(BinaryOperator::Cre<wbr>ateFDiv(L, R), FPMD, FMF);<br>
+ return Insert(I, Name);<br>
+ }<br>
+ /// Copy fast-math-flags from an instruction rather than using the builder's<br>
+ /// default FMF.<br>
+ Value *CreateFDivFMF(Value *L, Value *R, Instruction *FMFSource,<br>
+ const Twine &Name = "") {<br>
+ if (Value *V = foldConstant(Instruction::FDiv<wbr>, L, R, Name)) return V;<br>
+ Instruction *I = setFPAttrs(BinaryOperator::Cre<wbr>ateFDiv(L, R), nullptr,<br>
+ FMFSource->getFastMathFlags())<wbr>;<br>
+ return Insert(I, Name);<br>
+ }<br>
+ Value *CreateFRem(Value *L, Value *R, const Twine &Name = "",<br>
+ MDNode *FPMD = nullptr) {<br>
+ if (Value *V = foldConstant(Instruction::FRem<wbr>, L, R, Name)) return V;<br>
+ Instruction *I = setFPAttrs(BinaryOperator::Cre<wbr>ateFRem(L, R), FPMD, FMF);<br>
+ return Insert(I, Name);<br>
+ }<br>
+ /// Copy fast-math-flags from an instruction rather than using the builder's<br>
+ /// default FMF.<br>
+ Value *CreateFRemFMF(Value *L, Value *R, Instruction *FMFSource,<br>
+ const Twine &Name = "") {<br>
+ if (Value *V = foldConstant(Instruction::FRem<wbr>, L, R, Name)) return V;<br>
+ Instruction *I = setFPAttrs(BinaryOperator::Cre<wbr>ateFRem(L, R), nullptr,<br>
+ FMFSource->getFastMathFlags())<wbr>;<br>
+ return Insert(I, Name);<br>
+ }<br>
<br>
Value *CreateBinOp(Instruction::Bina<wbr>ryOps Opc,<br>
Value *LHS, Value *RHS, const Twine &Name = "",<br>
MDNode *FPMathTag = nullptr) {<br>
- if (Constant *LC = dyn_cast<Constant>(LHS))<br>
- if (Constant *RC = dyn_cast<Constant>(RHS))<br>
- return Insert(Folder.CreateBinOp(Opc, LC, RC), Name);<br>
+ if (Value *V = foldConstant(Opc, LHS, RHS, Name)) return V;<br>
Instruction *BinOp = BinaryOperator::Create(Opc, LHS, RHS);<br>
if (isa<FPMathOperator>(BinOp))<br>
- BinOp = AddFPMathAttributes(BinOp, FPMathTag, FMF);<br>
+ BinOp = setFPAttrs(BinOp, FPMathTag, FMF);<br>
return Insert(BinOp, Name);<br>
}<br>
<br>
@@ -1179,8 +1211,8 @@ public:<br>
MDNode *FPMathTag = nullptr) {<br>
if (Constant *VC = dyn_cast<Constant>(V))<br>
return Insert(Folder.CreateFNeg(VC), Name);<br>
- return Insert(AddFPMathAttributes(Bin<wbr>aryOperator::CreateFNeg(V),<br>
- FPMathTag, FMF), Name);<br>
+ return Insert(setFPAttrs(BinaryOperat<wbr>or::CreateFNeg(V), FPMathTag, FMF),<br>
+ Name);<br>
}<br>
Value *CreateNot(Value *V, const Twine &Name = "") {<br>
if (Constant *VC = dyn_cast<Constant>(V))<br>
@@ -1686,8 +1718,7 @@ public:<br>
if (Constant *LC = dyn_cast<Constant>(LHS))<br>
if (Constant *RC = dyn_cast<Constant>(RHS))<br>
return Insert(Folder.CreateFCmp(P, LC, RC), Name);<br>
- return Insert(AddFPMathAttributes(new FCmpInst(P, LHS, RHS),<br>
- FPMathTag, FMF), Name);<br>
+ return Insert(setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMF), Name);<br>
}<br>
<br>
//===------------------------<wbr>------------------------------<wbr>--------------===//<br>
@@ -1711,7 +1742,7 @@ public:<br>
MDNode *FPMathTag = nullptr) {<br>
CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);<br>
if (isa<FPMathOperator>(CI))<br>
- CI = cast<CallInst>(AddFPMathAttrib<wbr>utes(CI, FPMathTag, FMF));<br>
+ CI = cast<CallInst>(setFPAttrs(CI, FPMathTag, FMF));<br>
return Insert(CI, Name);<br>
}<br>
<br>
@@ -1720,7 +1751,7 @@ public:<br>
const Twine &Name = "", MDNode *FPMathTag = nullptr) {<br>
CallInst *CI = CallInst::Create(Callee, Args, OpBundles);<br>
if (isa<FPMathOperator>(CI))<br>
- CI = cast<CallInst>(AddFPMathAttrib<wbr>utes(CI, FPMathTag, FMF));<br>
+ CI = cast<CallInst>(setFPAttrs(CI, FPMathTag, FMF));<br>
return Insert(CI, Name);<br>
}<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div></div>
</blockquote></div><br></div></div>