[llvm] r287976 - add optional param to copy metadata when creating selects; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 26 07:02:01 PST 2016
Author: spatel
Date: Sat Nov 26 09:01:59 2016
New Revision: 287976
URL: http://llvm.org/viewvc/llvm-project?rev=287976&view=rev
Log:
add optional param to copy metadata when creating selects; NFC
There are other spots where we can use this; we're currently dropping
metadata in some places, and there are proposed changes where we will
want to propagate metadata.
IRBuilder's CreateSelect() already has a parameter like this, so this
change makes the regular 'Create' API line up with that.
Modified:
llvm/trunk/include/llvm/IR/Instructions.h
llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
Modified: llvm/trunk/include/llvm/IR/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Instructions.h?rev=287976&r1=287975&r2=287976&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Instructions.h (original)
+++ llvm/trunk/include/llvm/IR/Instructions.h Sat Nov 26 09:01:59 2016
@@ -1904,9 +1904,14 @@ protected:
public:
static SelectInst *Create(Value *C, Value *S1, Value *S2,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
- return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
+ Instruction *InsertBefore = nullptr,
+ Instruction *MDFrom = nullptr) {
+ SelectInst *Sel = new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
+ if (MDFrom)
+ Sel->copyMetadata(*MDFrom);
+ return Sel;
}
+
static SelectInst *Create(Value *C, Value *S1, Value *S2,
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp?rev=287976&r1=287975&r2=287976&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp Sat Nov 26 09:01:59 2016
@@ -531,8 +531,7 @@ canonicalizeMinMaxWithConstant(SelectIns
std::swap(LHS, RHS);
Value *NewCmp = Builder.CreateICmp(NewPred, LHS, RHS);
- SelectInst *NewSel = SelectInst::Create(NewCmp, LHS, RHS);
- NewSel->copyMetadata(Sel);
+ SelectInst *NewSel = SelectInst::Create(NewCmp, LHS, RHS, "", nullptr, &Sel);
// We swapped the select operands, so swap the metadata too.
NewSel->swapProfMetadata();
@@ -995,21 +994,18 @@ Instruction *InstCombiner::foldSelectExt
// If one arm of the select is the extend of the condition, replace that arm
// with the extension of the appropriate known bool value.
if (Cond == X) {
- SelectInst *NewSel;
if (ExtInst == Sel.getTrueValue()) {
// select X, (sext X), C --> select X, -1, C
// select X, (zext X), C --> select X, 1, C
Constant *One = ConstantInt::getTrue(SmallType);
Constant *AllOnesOrOne = ConstantExpr::getCast(ExtOpcode, One, SelType);
- NewSel = SelectInst::Create(Cond, AllOnesOrOne, C);
+ return SelectInst::Create(Cond, AllOnesOrOne, C, "", nullptr, &Sel);
} else {
// select X, C, (sext X) --> select X, C, 0
// select X, C, (zext X) --> select X, C, 0
Constant *Zero = ConstantInt::getNullValue(SelType);
- NewSel = SelectInst::Create(Cond, C, Zero);
+ return SelectInst::Create(Cond, C, Zero, "", nullptr, &Sel);
}
- NewSel->copyMetadata(Sel);
- return NewSel;
}
return nullptr;
More information about the llvm-commits
mailing list