[llvm] r335157 - [IR] add/use isIntDivRem convenience function
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 20 12:02:17 PDT 2018
Author: spatel
Date: Wed Jun 20 12:02:17 2018
New Revision: 335157
URL: http://llvm.org/viewvc/llvm-project?rev=335157&view=rev
Log:
[IR] add/use isIntDivRem convenience function
There are more existing potential users of this,
but I've limited this patch to the first couple
that I found to minimize typo risk.
Modified:
llvm/trunk/include/llvm/IR/Instruction.h
llvm/trunk/lib/IR/ConstantFold.cpp
llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
Modified: llvm/trunk/include/llvm/IR/Instruction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Instruction.h?rev=335157&r1=335156&r2=335157&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Instruction.h (original)
+++ llvm/trunk/include/llvm/IR/Instruction.h Wed Jun 20 12:02:17 2018
@@ -128,6 +128,7 @@ public:
const char *getOpcodeName() const { return getOpcodeName(getOpcode()); }
bool isTerminator() const { return isTerminator(getOpcode()); }
bool isBinaryOp() const { return isBinaryOp(getOpcode()); }
+ bool isIntDivRem() const { return isIntDivRem(getOpcode()); }
bool isShift() { return isShift(getOpcode()); }
bool isCast() const { return isCast(getOpcode()); }
bool isFuncletPad() const { return isFuncletPad(getOpcode()); }
@@ -142,6 +143,10 @@ public:
return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd;
}
+ static inline bool isIntDivRem(unsigned Opcode) {
+ return Opcode == UDiv || Opcode == SDiv || Opcode == URem || Opcode == SRem;
+ }
+
/// Determine if the Opcode is one of the shift instructions.
static inline bool isShift(unsigned Opcode) {
return Opcode >= Shl && Opcode <= AShr;
Modified: llvm/trunk/lib/IR/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantFold.cpp?rev=335157&r1=335156&r2=335157&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp (original)
+++ llvm/trunk/lib/IR/ConstantFold.cpp Wed Jun 20 12:02:17 2018
@@ -1227,9 +1227,7 @@ Constant *llvm::ConstantFoldBinaryInstru
Constant *RHS = ConstantExpr::getExtractElement(C2, ExtractIdx);
// If any element of a divisor vector is zero, the whole op is undef.
- if ((Opcode == Instruction::SDiv || Opcode == Instruction::UDiv ||
- Opcode == Instruction::SRem || Opcode == Instruction::URem) &&
- RHS->isNullValue())
+ if (Instruction::isIntDivRem(Opcode) && RHS->isNullValue())
return UndefValue::get(VTy);
Result.push_back(ConstantExpr::get(Opcode, LHS, RHS));
Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=335157&r1=335156&r2=335157&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Wed Jun 20 12:02:17 2018
@@ -1423,9 +1423,7 @@ Instruction *InstCombiner::foldShuffledB
// undefined behavior. All other binop opcodes are always safe to
// speculate, and therefore, it is fine to include undef elements for
// unused lanes (and using undefs may help optimization).
- BinaryOperator::BinaryOps Opcode = Inst.getOpcode();
- if (Opcode == Instruction::UDiv || Opcode == Instruction::URem ||
- Opcode == Instruction::SDiv || Opcode == Instruction::SRem) {
+ if (Inst.isIntDivRem()) {
assert(C->getType()->getScalarType()->isIntegerTy() &&
"Not expecting FP opcodes/operands/constants here");
for (unsigned i = 0; i < VWidth; ++i)
More information about the llvm-commits
mailing list