LLVM
8.0.1
|
#include "llvm/Transforms/Scalar/Reassociate.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include <algorithm>
#include <cassert>
#include <utility>
Go to the source code of this file.
Classes | |
class | llvm::reassociate::XorOpnd |
Utility class representing a non-constant Xor-operand. More... | |
Macros | |
#define | DEBUG_TYPE "reassociate" |
Typedefs | |
using | RepeatedValue = std::pair< Value *, APInt > |
Functions | |
STATISTIC (NumChanged, "Number of insts reassociated") | |
STATISTIC (NumAnnihil, "Number of expr tree annihilated") | |
STATISTIC (NumFactor, "Number of multiplies factored") | |
static void | PrintOps (Instruction *I, const SmallVectorImpl< ValueEntry > &Ops) |
Print out the expression identified in the Ops list. More... | |
static BinaryOperator * | isReassociableOp (Value *V, unsigned Opcode) |
Return true if V is an instruction of the specified opcode and if it only has one use. More... | |
static BinaryOperator * | isReassociableOp (Value *V, unsigned Opcode1, unsigned Opcode2) |
static BinaryOperator * | CreateAdd (Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp) |
static BinaryOperator * | CreateMul (Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp) |
static BinaryOperator * | CreateNeg (Value *S1, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp) |
static BinaryOperator * | LowerNegateToMultiply (Instruction *Neg) |
Replace 0-X with X*-1. More... | |
static unsigned | CarmichaelShift (unsigned Bitwidth) |
Returns k such that lambda(2^Bitwidth) = 2^k, where lambda is the Carmichael function. More... | |
static void | IncorporateWeight (APInt &LHS, const APInt &RHS, unsigned Opcode) |
Add the extra weight 'RHS' to the existing weight 'LHS', reducing the combined weight using any special properties of the operation. More... | |
static bool | LinearizeExprTree (BinaryOperator *I, SmallVectorImpl< RepeatedValue > &Ops) |
Given an associative binary expression, return the leaf nodes in Ops along with their weights (how many times the leaf occurs). More... | |
static Value * | NegateValue (Value *V, Instruction *BI, ReassociatePass::OrderedSet &ToRedo) |
Insert instructions before the instruction pointed to by BI, that computes the negative version of the value specified. More... | |
static bool | ShouldBreakUpSubtract (Instruction *Sub) |
Return true if we should break up this subtract of X-Y into (X + -Y). More... | |
static BinaryOperator * | BreakUpSubtract (Instruction *Sub, ReassociatePass::OrderedSet &ToRedo) |
If we have (X-Y), and if either X is an add, or if this is only used by an add, transform this into (X+(0-Y)) to promote better reassociation. More... | |
static BinaryOperator * | ConvertShiftToMul (Instruction *Shl) |
If this is a shift of a reassociable multiply or is used by one, change this into a multiply by a constant to assist with further reassociation. More... | |
static unsigned | FindInOperandList (const SmallVectorImpl< ValueEntry > &Ops, unsigned i, Value *X) |
Scan backwards and forwards among values with the same rank as element i to see if X exists. More... | |
static Value * | EmitAddTreeOfValues (Instruction *I, SmallVectorImpl< WeakTrackingVH > &Ops) |
Emit a tree of add instructions, summing Ops together and returning the result. More... | |
static void | FindSingleUseMultiplyFactors (Value *V, SmallVectorImpl< Value *> &Factors) |
If V is a single-use multiply, recursively add its operands as factors, otherwise add V to the list of factors. More... | |
static Value * | OptimizeAndOrXor (unsigned Opcode, SmallVectorImpl< ValueEntry > &Ops) |
Optimize a series of operands to an 'and', 'or', or 'xor' instruction. More... | |
static Value * | createAndInstr (Instruction *InsertBefore, Value *Opnd, const APInt &ConstOpnd) |
Helper function of CombineXorOpnd(). More... | |
static bool | collectMultiplyFactors (SmallVectorImpl< ValueEntry > &Ops, SmallVectorImpl< Factor > &Factors) |
Build up a vector of value/power pairs factoring a product. More... | |
static Value * | buildMultiplyTree (IRBuilder<> &Builder, SmallVectorImpl< Value *> &Ops) |
Build a tree of multiplies, computing the product of Ops. More... | |
INITIALIZE_PASS (ReassociateLegacyPass, "reassociate", "Reassociate expressions", false, false) FunctionPass *llvm | |
#define DEBUG_TYPE "reassociate" |
Definition at line 68 of file Reassociate.cpp.
using RepeatedValue = std::pair<Value*, APInt> |
Definition at line 373 of file Reassociate.cpp.
|
static |
If we have (X-Y), and if either X is an add, or if this is only used by an add, transform this into (X+(0-Y)) to promote better reassociation.
Definition at line 925 of file Reassociate.cpp.
References CreateAdd(), llvm::dbgs(), llvm::Constant::getNullValue(), llvm::User::getOperand(), LLVM_DEBUG, NegateValue(), and llvm::User::setOperand().
Referenced by buildMultiplyTree().
|
static |
Build a tree of multiplies, computing the product of Ops.
Definition at line 1698 of file Reassociate.cpp.
References llvm::MCID::Add, llvm::SmallVectorImpl< T >::append(), assert(), llvm::SmallVectorTemplateCommon< T, typename >::back(), llvm::SmallVectorTemplateCommon< T >::back(), llvm::SmallVectorTemplateCommon< T >::begin(), BreakUpSubtract(), C, llvm::APFloat::changeSign(), collectMultiplyFactors(), ConvertShiftToMul(), llvm::IRBuilder< T, Inserter >::CreateFMul(), llvm::IRBuilder< T, Inserter >::CreateMul(), llvm::dbgs(), llvm::Value::dump(), llvm::dyn_cast(), E, llvm::SmallVectorBase::empty(), llvm::sys::path::end(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::SmallVectorImpl< T >::erase(), llvm::Instruction::eraseFromParent(), llvm::SmallVectorTemplateCommon< T >::front(), llvm::ConstantFP::get(), llvm::ConstantExpr::get(), llvm::ConstantExpr::getBinOpAbsorber(), llvm::ConstantExpr::getBinOpIdentity(), llvm::Value::getContext(), llvm::Instruction::getDebugLoc(), llvm::Value::getName(), llvm::Instruction::getOpcode(), getOpcode(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::Value::getType(), llvm::ConstantFP::getValueAPF(), llvm::Value::hasOneUse(), I, llvm::SmallSet< T, N, C >::insert(), llvm::iplist_impl< IntrusiveListT, TraitsT >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::SmallVectorImpl< T >::insert(), llvm::Instruction::insertBefore(), llvm::Instruction::isAssociative(), llvm::Instruction::isCommutative(), llvm::Instruction::isFast(), llvm::Type::isFPOrFPVectorTy(), llvm::isInstructionTriviallyDead(), llvm::Type::isIntegerTy(), llvm::Type::isIntOrIntVectorTy(), llvm::ConstantFP::isNegative(), isReassociableOp(), llvm::Type::isVectorTy(), LinearizeExprTree(), LLVM_DEBUG, llvm_unreachable, llvm::lower_bound(), LowerNegateToMultiply(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::max(), MI, llvm::reassociate::ValueEntry::Op, llvm::User::op_begin(), llvm::User::op_end(), OptimizeAndOrXor(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::reassociate::Factor::Power, PrintOps(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::Value::replaceAllUsesWith(), llvm::SmallVectorImpl< T >::reserve(), llvm::Instruction::setDebugLoc(), llvm::IRBuilderBase::setFastMathFlags(), llvm::Instruction::setFastMathFlags(), llvm::Value::setName(), llvm::User::setOperand(), ShouldBreakUpSubtract(), Size, llvm::SmallVectorBase::size(), std::swap(), llvm::Value::use_empty(), llvm::Instruction::user_back(), llvm::Value::users(), and VI.
Returns k such that lambda(2^Bitwidth) = 2^k, where lambda is the Carmichael function.
This means that x^(2^k) === 1 mod 2^Bitwidth for every odd x, i.e. x^(2^k) = 1 for every odd x in Bitwidth-bit arithmetic. Note that 0 <= k < Bitwidth, and if Bitwidth > 3 then x^(2^k) = 0 for every even x in Bitwidth-bit arithmetic.
Definition at line 287 of file Reassociate.cpp.
Referenced by IncorporateWeight().
|
static |
Build up a vector of value/power pairs factoring a product.
Given a series of multiplication operands, build a vector of factors and the powers each is raised to when forming the final product. Sort them in the order of descending power.
(x*x) -> [(x, 2)] ((x*x)*x) -> [(x, 3)]
((((x*y)*x)*y)*x) -> [(x, 3), (y, 2)]
Definition at line 1643 of file Reassociate.cpp.
References assert(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::SmallVectorImpl< T >::erase(), llvm::reassociate::Factor::Power, llvm::SmallVectorTemplateBase< T >::push_back(), Size, and llvm::SmallVectorBase::size().
Referenced by buildMultiplyTree().
|
static |
If this is a shift of a reassociable multiply or is used by one, change this into a multiply by a constant to assist with further reassociation.
Definition at line 948 of file Reassociate.cpp.
References CreateMul(), llvm::ConstantInt::get(), llvm::UndefValue::get(), llvm::Instruction::getDebugLoc(), llvm::User::getOperand(), llvm::ConstantExpr::getShl(), llvm::Value::getType(), llvm::Value::replaceAllUsesWith(), llvm::Instruction::setDebugLoc(), llvm::Instruction::setHasNoSignedWrap(), llvm::Instruction::setHasNoUnsignedWrap(), llvm::User::setOperand(), and llvm::Value::takeName().
Referenced by buildMultiplyTree().
|
static |
Definition at line 233 of file Reassociate.cpp.
References llvm::Value::getType(), llvm::Type::isIntOrIntVectorTy(), and llvm::Instruction::setFastMathFlags().
Referenced by BreakUpSubtract(), canonicalizeSaturatedSubtract(), checkForNegativeOperand(), ConvertToSInt(), llvm::NoFolder::CreateAdd(), createAndInstr(), llvm::IRBuilder< TargetFolder >::CreateNSWAdd(), llvm::IRBuilder< TargetFolder >::CreateNUWAdd(), EmitAddTreeOfValues(), llvm::InnerLoopVectorizer::emitTransformedIndex(), isGEPFoldable(), LLVMBuildAdd(), llvm::PHITransAddr::PHITranslateWithInsertion(), llvm::InstCombiner::visitAdd(), llvm::InstCombiner::visitExtractValueInst(), llvm::InstCombiner::visitMul(), llvm::InstCombiner::visitSub(), and llvm::InstCombiner::visitXor().
|
static |
Helper function of CombineXorOpnd().
It creates a bitwise-and instruction with the given two operands, and return the resulting instruction. There are two special cases: 1) if the constant operand is 0, it will return NULL. 2) if the constant is ~0, the symbolic operand will be returned.
Definition at line 1154 of file Reassociate.cpp.
References assert(), llvm::SmallVectorTemplateCommon< T >::back(), llvm::SmallVectorTemplateCommon< T >::begin(), C, llvm::SmallVectorImpl< T >::clear(), CreateAdd(), CreateMul(), llvm::dbgs(), llvm::Value::deleteValue(), EmitAddTreeOfValues(), llvm::SmallVectorBase::empty(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::SmallVectorImpl< T >::erase(), F(), FindInOperandList(), FindSingleUseMultiplyFactors(), llvm::ConstantInt::get(), llvm::ConstantFP::get(), llvm::Constant::getAllOnesValue(), llvm::APInt::getBoolValue(), llvm::reassociate::XorOpnd::getConstPart(), llvm::Instruction::getDebugLoc(), llvm::Constant::getNullValue(), llvm::Type::getScalarSizeInBits(), llvm::reassociate::XorOpnd::getSymbolicPart(), llvm::reassociate::XorOpnd::getSymbolicRank(), llvm::Value::getType(), llvm::reassociate::XorOpnd::getValue(), llvm::Value::hasOneUse(), I, llvm::SmallVectorImpl< T >::insert(), llvm::reassociate::XorOpnd::Invalidate(), llvm::APInt::isAllOnesValue(), llvm::Type::isIntOrIntVectorTy(), llvm::reassociate::XorOpnd::isInvalid(), llvm::APInt::isNullValue(), llvm::reassociate::XorOpnd::isOrExpr(), isReassociableOp(), LLVM_DEBUG, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::RISCVFenceField::O, llvm::reassociate::ValueEntry::Op, OptimizeAndOrXor(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::Instruction::setDebugLoc(), llvm::reassociate::XorOpnd::setSymbolicRank(), llvm::SmallVectorBase::size(), std::swap(), llvm::NVPTX::PTXLdStInstCode::V2, VI, and X.
|
static |
Definition at line 245 of file Reassociate.cpp.
References llvm::Value::getType(), llvm::Type::isIntOrIntVectorTy(), and llvm::Instruction::setFastMathFlags().
Referenced by ConvertShiftToMul(), createAndInstr(), createMalloc(), llvm::NoFolder::CreateMul(), llvm::IRBuilder< TargetFolder >::CreateNSWMul(), llvm::IRBuilder< TargetFolder >::CreateNUWMul(), llvm::InnerLoopVectorizer::emitTransformedIndex(), isGEPFoldable(), LLVMBuildMul(), LowerNegateToMultiply(), optimizeDivRem(), llvm::InstCombiner::visitExtractValueInst(), llvm::InstCombiner::visitMul(), and llvm::InstCombiner::visitShl().
|
static |
Definition at line 257 of file Reassociate.cpp.
References llvm::BinaryOperator::CreateFNeg(), llvm::BinaryOperator::CreateNeg(), llvm::Value::getType(), llvm::Type::isIntOrIntVectorTy(), and llvm::Instruction::setFastMathFlags().
Referenced by llvm::IRBuilder< TargetFolder >::CreateNSWNeg(), llvm::IRBuilder< TargetFolder >::CreateNUWNeg(), EmitAddTreeOfValues(), LLVMBuildNeg(), and NegateValue().
|
static |
Emit a tree of add instructions, summing Ops together and returning the result.
Insert the tree before I.
Definition at line 1001 of file Reassociate.cpp.
References llvm::SmallVectorImpl< T >::append(), llvm::SmallVectorTemplateCommon< T >::back(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::APFloat::changeSign(), llvm::APFloatBase::cmpEqual, llvm::APFloat::compare(), CreateAdd(), CreateNeg(), E, llvm::SmallVectorImpl< T >::erase(), llvm::ilist_node_impl< OptionsT >::getIterator(), isReassociableOp(), LinearizeExprTree(), llvm::SmallVectorTemplateBase< T >::pop_back(), llvm::SmallVectorImpl< T >::reserve(), llvm::SmallVectorBase::size(), and llvm::NVPTX::PTXLdStInstCode::V2.
Referenced by createAndInstr().
|
static |
Scan backwards and forwards among values with the same rank as element i to see if X exists.
If X does not exist, return i. This is useful when scanning for 'x' when we see '-x' because they both get the same rank.
Definition at line 975 of file Reassociate.cpp.
References llvm::SmallVectorBase::size().
Referenced by createAndInstr(), and OptimizeAndOrXor().
|
static |
If V is a single-use multiply, recursively add its operands as factors, otherwise add V to the list of factors.
Ops is the top-level list of add operands we're trying to factor.
Definition at line 1088 of file Reassociate.cpp.
References llvm::User::getOperand(), isReassociableOp(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by createAndInstr().
Add the extra weight 'RHS' to the existing weight 'LHS', reducing the combined weight using any special properties of the operation.
The existing weight LHS represents the computation X op X op ... op X where X occurs LHS times. The combined weight represents X op X op ... op X with X occurring LHS + RHS times. If op is "Xor" for example then the combined operation is equivalent to X if LHS + RHS is odd, or 0 if LHS + RHS is even; the routine returns 1 in LHS in the first case, and 0 in LHS in the second.
CM - The value of Carmichael's lambda function.
Definition at line 300 of file Reassociate.cpp.
References llvm::MCID::Add, assert(), CarmichaelShift(), llvm::APInt::getBitWidth(), llvm::APInt::getOneBitSet(), llvm::APInt::getZExtValue(), llvm::Instruction::isIdempotent(), llvm::APInt::isMinValue(), llvm::Instruction::isNilpotent(), Threshold, and llvm::APInt::ult().
Referenced by LinearizeExprTree().
INITIALIZE_PASS | ( | ReassociateLegacyPass | , |
"reassociate" | , | ||
"Reassociate expressions" | , | ||
false | , | ||
false | |||
) |
Definition at line 2410 of file Reassociate.cpp.
|
static |
Return true if V is an instruction of the specified opcode and if it only has one use.
Definition at line 148 of file Reassociate.cpp.
References llvm::dyn_cast(), and I.
Referenced by buildMultiplyTree(), createAndInstr(), EmitAddTreeOfValues(), FindSingleUseMultiplyFactors(), LinearizeExprTree(), NegateValue(), and ShouldBreakUpSubtract().
|
static |
Definition at line 156 of file Reassociate.cpp.
References Arg, llvm::Function::args(), assert(), llvm::dbgs(), llvm::dyn_cast(), F(), llvm::Value::getName(), llvm::User::getOperand(), I, llvm::Instruction::isCommutative(), LLVM_DEBUG, llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::max(), and llvm::mayBeMemoryDependent().
|
static |
Given an associative binary expression, return the leaf nodes in Ops along with their weights (how many times the leaf occurs).
The original expression is the same as (Ops[0].first op Ops[0].first op ... Ops[0].first) <- Ops[0].second times op (Ops[1].first op Ops[1].first op ... Ops[1].first) <- Ops[1].second times op ... op (Ops[N].first op Ops[N].first op ... Ops[N].first) <- Ops[N].second times
Note that the values Ops[0].first, ..., Ops[N].first are all distinct.
This routine may modify the function, in which case it returns 'true'. The changes it makes may well be destructive, changing the value computed by 'I' to something completely different. Thus if the routine returns 'true' then you MUST either replace I with a new expression computed from the Ops array, or use RewriteExprTree to put the values back in.
A leaf node is either not a binary operation of the same kind as the root node 'I' (i.e. is not a binary operator at all, or is, but with a different opcode), or is the same kind of binary operator but has a use which either does not belong to the expression, or does belong to the expression but is a leaf node. Every leaf node has at least one use that is a non-leaf node of the expression, while for non-leaf nodes (except for the root 'I') every use is a non-leaf node of the expression.
For example: expression graph node names
+ | I / \ | + + | A, B / \ / \ | * + * | C, D, E / \ / \ / \ | + * | F, G
The leaf nodes are C, E, F and G. The Ops array will contain (maybe not in that order) (C, 1), (E, 1), (F, 2), (G, 2).
The expression is maximal: if some instruction is a binary operator of the same kind as 'I', and all of its uses are non-leaf nodes of the expression, then the instruction also belongs to the expression, is not a leaf node of it, and its operands also belong to the expression (but may be leaf nodes).
NOTE: This routine will set operands of non-leaf non-root nodes to undef in order to ensure that every non-root node in the expression has exactly one use by a non-leaf node of the expression. This destruction means that the caller MUST either replace 'I' with a new expression or use something like RewriteExprTree to put the values back in if the routine indicates that it made a change by returning 'true'.
In the above example either the right operand of A or the left operand of B will be replaced by undef. If it is B's operand then this gives:
+ | I / \ | + + | A, B - operand of B replaced with undef / \ \ | * + * | C, D, E / \ / \ / \ | + * | F, G
Note that such undef operands can only be reached by passing through 'I'. For example, if you visit operands recursively starting from a leaf node then you will never see such an undef operand unless you get back to 'I', which requires passing through a phi node.
Note that this routine may also mutate binary operators of the wrong type that have all uses inside the expression (i.e. only used by non-leaf nodes of the expression) if it can turn them into binary operators of the right type and thus make the expression bigger.
Definition at line 448 of file Reassociate.cpp.
References assert(), llvm::Value::clearSubclassOptionalData(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::BinaryOperator::Create(), llvm::dbgs(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::SmallVectorBase::empty(), llvm::UndefValue::get(), llvm::ConstantExpr::getBinOpIdentity(), llvm::Instruction::getFastMathFlags(), getOpcode(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Type::getPrimitiveSizeInBits(), llvm::Type::getScalarType(), llvm::Value::getType(), llvm::Value::hasOneUse(), I, IncorporateWeight(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::Instruction::isAssociative(), llvm::Instruction::isCommutative(), llvm::APInt::isMinValue(), isReassociableOp(), LLVM_DEBUG, LowerNegateToMultiply(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Instruction::moveBefore(), P, llvm::SmallVectorTemplateBase< T >::push_back(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::replaceDbgUsesWithUndef(), llvm::Instruction::setFastMathFlags(), llvm::User::setOperand(), llvm::SmallVectorBase::size(), llvm::BinaryOperator::swapOperands(), llvm::RegState::Undef, llvm::Value::use_empty(), and llvm::Value::user_begin().
Referenced by buildMultiplyTree(), and EmitAddTreeOfValues().
|
static |
Replace 0-X with X*-1.
Definition at line 269 of file Reassociate.cpp.
References CreateMul(), llvm::ConstantFP::get(), llvm::Constant::getAllOnesValue(), llvm::Constant::getNullValue(), llvm::User::getOperand(), llvm::Value::getType(), llvm::Type::isIntOrIntVectorTy(), llvm::Instruction::setDebugLoc(), llvm::User::setOperand(), and llvm::Value::takeName().
Referenced by buildMultiplyTree(), and LinearizeExprTree().
|
static |
Insert instructions before the instruction pointed to by BI, that computes the negative version of the value specified.
The negative version of the value is returned, and BI is left pointing at the instruction that should be processed next by the reassociation pass. Also add intermediate instructions to the redo list that are modified while pushing the negates through adds. These will be revisited to see if additional opportunities have been exposed.
Definition at line 810 of file Reassociate.cpp.
References llvm::MCID::Add, llvm::Instruction::andIRFlags(), llvm::BasicBlock::begin(), C, CreateNeg(), llvm::Function::getEntryBlock(), llvm::ConstantExpr::getFNeg(), llvm::Value::getName(), llvm::ConstantExpr::getNeg(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::Value::getType(), I, llvm::Type::isFPOrFPVectorTy(), isReassociableOp(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Instruction::moveBefore(), llvm::Instruction::setHasNoSignedWrap(), llvm::Instruction::setHasNoUnsignedWrap(), llvm::Value::setName(), llvm::User::setOperand(), and llvm::Value::users().
Referenced by BreakUpSubtract().
|
static |
Optimize a series of operands to an 'and', 'or', or 'xor' instruction.
This optimizes based on identities. If it can be reduced to a single Value, it is returned, otherwise the Ops list is mutated as necessary.
Definition at line 1104 of file Reassociate.cpp.
References assert(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::SmallVectorImpl< T >::erase(), FindInOperandList(), llvm::Constant::getAllOnesValue(), llvm::Constant::getNullValue(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::SmallVectorBase::size(), and X.
Referenced by buildMultiplyTree(), and createAndInstr().
|
static |
Print out the expression identified in the Ops list.
Definition at line 76 of file Reassociate.cpp.
References llvm::dbgs(), llvm::Instruction::getModule(), llvm::Instruction::getOpcode(), llvm::Instruction::getOpcodeName(), and llvm::SmallVectorBase::size().
Referenced by buildMultiplyTree().
|
static |
Return true if we should break up this subtract of X-Y into (X + -Y).
Definition at line 895 of file Reassociate.cpp.
References llvm::MCID::Add, llvm::User::getOperand(), llvm::Value::hasOneUse(), isReassociableOp(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Instruction::user_back(), and llvm::codeview::VB.
Referenced by buildMultiplyTree().
STATISTIC | ( | NumChanged | , |
"Number of insts reassociated" | |||
) |
STATISTIC | ( | NumAnnihil | , |
"Number of expr tree annihilated" | |||
) |
STATISTIC | ( | NumFactor | , |
"Number of multiplies factored" | |||
) |