[PATCH] D62534: [LoopVectorize] Merge UnaryOperator and BinaryOperator handling
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 28 10:53:54 PDT 2019
craig.topper created this revision.
craig.topper added reviewers: fhahn, cameron.mcinally, spatel, RKSimon, hsaito.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
This is a follow up to D62510 <https://reviews.llvm.org/D62510> where UnaryOperator was added. It was suggested that we have common handling for UnaryOperator and BinaryOperator
https://reviews.llvm.org/D62534
Files:
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -3969,6 +3969,7 @@
case Instruction::FAdd:
case Instruction::Sub:
case Instruction::FSub:
+ case Instruction::FNeg:
case Instruction::Mul:
case Instruction::FMul:
case Instruction::FDiv:
@@ -3979,40 +3980,23 @@
case Instruction::And:
case Instruction::Or:
case Instruction::Xor: {
- // Just widen binops.
- auto *BinOp = cast<BinaryOperator>(&I);
- setDebugLocFromInst(Builder, BinOp);
-
- for (unsigned Part = 0; Part < UF; ++Part) {
- Value *A = getOrCreateVectorValue(BinOp->getOperand(0), Part);
- Value *B = getOrCreateVectorValue(BinOp->getOperand(1), Part);
- Value *V = Builder.CreateBinOp(BinOp->getOpcode(), A, B);
-
- if (BinaryOperator *VecOp = dyn_cast<BinaryOperator>(V))
- VecOp->copyIRFlags(BinOp);
-
- // Use this vector value for all users of the original instruction.
- VectorLoopValueMap.setVectorValue(&I, Part, V);
- addMetadata(V, BinOp);
- }
-
- break;
- }
- case Instruction::FNeg: {
- // Just widen unary ops.
- auto *UnOp = cast<UnaryOperator>(&I);
- setDebugLocFromInst(Builder, UnOp);
+ // Just widen unops and binops.
+ setDebugLocFromInst(Builder, &I);
for (unsigned Part = 0; Part < UF; ++Part) {
- Value *A = getOrCreateVectorValue(UnOp->getOperand(0), Part);
- Value *V = Builder.CreateUnOp(UnOp->getOpcode(), A);
+ SmallVector<Value *, 2> Ops;
+ for (unsigned i = 0; i != I.getNumOperands(); ++i) {
+ Value *V = getOrCreateVectorValue(I.getOperand(i), Part);
+ Ops.push_back(V);
+ }
+ Value *V = Builder.CreateNAryOp(I.getOpcode(), Ops);
- if (UnaryOperator *VecOp = dyn_cast<UnaryOperator>(V))
- VecOp->copyIRFlags(UnOp);
+ if (auto *VecOp = dyn_cast<Instruction>(V))
+ VecOp->copyIRFlags(&I);
// Use this vector value for all users of the original instruction.
VectorLoopValueMap.setVectorValue(&I, Part, V);
- addMetadata(V, UnOp);
+ addMetadata(V, &I);
}
break;
Index: llvm/include/llvm/IR/IRBuilder.h
===================================================================
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -1383,6 +1383,22 @@
return Insert(UnOp, Name);
}
+ Value *CreateNAryOp(unsigned Opc, ArrayRef<Value *> Ops,
+ const Twine &Name = "",
+ MDNode *FPMathTag = nullptr) {
+ if (Instruction::isBinaryOp(Opc)) {
+ assert(Ops.size() == 2 && "Invalid number of operands!");
+ return CreateBinOp(static_cast<Instruction::BinaryOps>(Opc),
+ Ops[0], Ops[1], Name, FPMathTag);
+ }
+ if (Instruction::isUnaryOp(Opc)) {
+ assert(Ops.size() == 1 && "Invalid number of operands!");
+ return CreateUnOp(static_cast<Instruction::UnaryOps>(Opc),
+ Ops[0], Name, FPMathTag);
+ }
+ llvm_unreachable("Unexpected opcode!");
+ }
+
//===--------------------------------------------------------------------===//
// Instruction creation methods: Memory Instructions
//===--------------------------------------------------------------------===//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62534.201713.patch
Type: text/x-patch
Size: 3398 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190528/94823806/attachment.bin>
More information about the llvm-commits
mailing list