[llvm] r343694 - [InstCombine] clean up foldVectorBinop(); NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 3 08:46:04 PDT 2018
Author: spatel
Date: Wed Oct 3 08:46:03 2018
New Revision: 343694
URL: http://llvm.org/viewvc/llvm-project?rev=343694&view=rev
Log:
[InstCombine] clean up foldVectorBinop(); NFC
1. Fix include ordering.
2. Improve variable name (width is bitwidth not number-of-elements).
3. Add local Opcode variable to reduce code duplication.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=343694&r1=343693&r2=343694&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Wed Oct 3 08:46:03 2018
@@ -57,7 +57,6 @@
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/TargetFolder.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
-#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
@@ -97,6 +96,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/InstCombine/InstCombine.h"
#include "llvm/Transforms/InstCombine/InstCombineWorklist.h"
+#include "llvm/Transforms/Utils/Local.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
@@ -1354,10 +1354,11 @@ Value *InstCombiner::Descale(Value *Val,
Instruction *InstCombiner::foldVectorBinop(BinaryOperator &Inst) {
if (!Inst.getType()->isVectorTy()) return nullptr;
- unsigned VWidth = cast<VectorType>(Inst.getType())->getNumElements();
+ BinaryOperator::BinaryOps Opcode = Inst.getOpcode();
+ unsigned NumElts = cast<VectorType>(Inst.getType())->getNumElements();
Value *LHS = Inst.getOperand(0), *RHS = Inst.getOperand(1);
- assert(cast<VectorType>(LHS->getType())->getNumElements() == VWidth);
- assert(cast<VectorType>(RHS->getType())->getNumElements() == VWidth);
+ assert(cast<VectorType>(LHS->getType())->getNumElements() == NumElts);
+ assert(cast<VectorType>(RHS->getType())->getNumElements() == NumElts);
// If both operands of the binop are vector concatenations, then perform the
// narrow binop on each pair of the source operands followed by concatenation
@@ -1373,10 +1374,10 @@ Instruction *InstCombiner::foldVectorBin
// operating on exactly the same elements as the existing binop.
// TODO: We could ease the mask requirement to allow different undef lanes,
// but that requires an analysis of the binop-with-undef output value.
- Value *NewBO0 = Builder.CreateBinOp(Inst.getOpcode(), L0, R0);
+ Value *NewBO0 = Builder.CreateBinOp(Opcode, L0, R0);
if (auto *BO = dyn_cast<BinaryOperator>(NewBO0))
BO->copyIRFlags(&Inst);
- Value *NewBO1 = Builder.CreateBinOp(Inst.getOpcode(), L1, R1);
+ Value *NewBO1 = Builder.CreateBinOp(Opcode, L1, R1);
if (auto *BO = dyn_cast<BinaryOperator>(NewBO1))
BO->copyIRFlags(&Inst);
return new ShuffleVectorInst(NewBO0, NewBO1, Mask);
@@ -1389,7 +1390,7 @@ Instruction *InstCombiner::foldVectorBin
return nullptr;
auto createBinOpShuffle = [&](Value *X, Value *Y, Constant *M) {
- Value *XY = Builder.CreateBinOp(Inst.getOpcode(), X, Y);
+ Value *XY = Builder.CreateBinOp(Opcode, X, Y);
if (auto *BO = dyn_cast<BinaryOperator>(XY))
BO->copyIRFlags(&Inst);
return new ShuffleVectorInst(XY, UndefValue::get(XY->getType()), M);
@@ -1415,7 +1416,7 @@ Instruction *InstCombiner::foldVectorBin
if (match(&Inst, m_c_BinOp(
m_OneUse(m_ShuffleVector(m_Value(V1), m_Undef(), m_Constant(Mask))),
m_Constant(C))) &&
- V1->getType()->getVectorNumElements() <= VWidth) {
+ V1->getType()->getVectorNumElements() <= NumElts) {
assert(Inst.getType()->getScalarType() == V1->getType()->getScalarType() &&
"Shuffle should not change scalar type");
unsigned V1Width = V1->getType()->getVectorNumElements();
@@ -1429,9 +1430,9 @@ Instruction *InstCombiner::foldVectorBin
SmallVector<Constant *, 16>
NewVecC(V1Width, UndefValue::get(C->getType()->getScalarType()));
bool MayChange = true;
- for (unsigned I = 0; I < VWidth; ++I) {
+ for (unsigned I = 0; I < NumElts; ++I) {
if (ShMask[I] >= 0) {
- assert(ShMask[I] < (int)VWidth && "Not expecting narrowing shuffle");
+ assert(ShMask[I] < (int)NumElts && "Not expecting narrowing shuffle");
Constant *CElt = C->getAggregateElement(I);
Constant *NewCElt = NewVecC[ShMask[I]];
// Bail out if:
@@ -1455,7 +1456,7 @@ Instruction *InstCombiner::foldVectorBin
// that did not exist in the original code.
bool ConstOp1 = isa<Constant>(Inst.getOperand(1));
if (Inst.isIntDivRem() || (Inst.isShift() && ConstOp1))
- NewC = getSafeVectorConstantForBinop(Inst.getOpcode(), NewC, ConstOp1);
+ NewC = getSafeVectorConstantForBinop(Opcode, NewC, ConstOp1);
// Op(shuffle(V1, Mask), C) -> shuffle(Op(V1, NewC), Mask)
// Op(C, shuffle(V1, Mask)) -> shuffle(Op(NewC, V1), Mask)
More information about the llvm-commits
mailing list