llvm.org GIT mirror llvm / ec4e85e
Refactor operation equivalence checking in BBVectorize by extending Instruction::isSameOperationAs. Maintaining this kind of checking in different places is dangerous, extending Instruction::isSameOperationAs consolidates this logic into one place. Here I've added an optional flags parameter and two flags that are important for vectorization: CompareIgnoringAlignment and CompareUsingScalarTypes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159329 91177308-0d34-0410-b5e6-96231b3b80d8 Hal Finkel 7 years ago
3 changed file(s) with 29 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
280280 /// ignores the SubclassOptionalData flags, which specify conditions
281281 /// under which the instruction's result is undefined.
282282 bool isIdenticalToWhenDefined(const Instruction *I) const;
283
284 /// When checking for operation equivalence (using isSameOperationAs) it is
285 /// sometimes useful to ignore certain attributes.
286 enum OperationEquivalenceFlags {
287 /// Check for equivalence ignoring load/store alignment.
288 CompareIgnoringAlignment = 1<<0,
289 /// Check for equivalence treating a type and a vector of that type
290 /// as equivalent.
291 CompareUsingScalarTypes = 1<<1
292 };
283293
284294 /// This function determines if the specified instruction executes the same
285295 /// operation as the current one. This means that the opcodes, type, operand
289299 /// @returns true if the specified instruction is the same operation as
290300 /// the current one.
291301 /// @brief Determine if one instruction is the same operation as another.
292 bool isSameOperationAs(const Instruction *I) const;
302 bool isSameOperationAs(const Instruction *I, unsigned flags = 0) const;
293303
294304 /// isUsedOutsideOfBlock - Return true if there are any uses of this
295305 /// instruction in blocks other than the specified block. Note that PHI nodes
659659
660660 // Loads and stores can be merged if they have different alignments,
661661 // but are otherwise the same.
662 LoadInst *LI, *LJ;
663 StoreInst *SI, *SJ;
664 if ((LI = dyn_cast(I)) && (LJ = dyn_cast(J))) {
665 if (I->getType() != J->getType())
666 return false;
667
668 if (LI->getPointerOperand()->getType() !=
669 LJ->getPointerOperand()->getType() ||
670 LI->isVolatile() != LJ->isVolatile() ||
671 LI->getOrdering() != LJ->getOrdering() ||
672 LI->getSynchScope() != LJ->getSynchScope())
673 return false;
674 } else if ((SI = dyn_cast(I)) && (SJ = dyn_cast(J))) {
675 if (SI->getValueOperand()->getType() !=
676 SJ->getValueOperand()->getType() ||
677 SI->getPointerOperand()->getType() !=
678 SJ->getPointerOperand()->getType() ||
679 SI->isVolatile() != SJ->isVolatile() ||
680 SI->getOrdering() != SJ->getOrdering() ||
681 SI->getSynchScope() != SJ->getSynchScope())
682 return false;
683 } else if (!J->isSameOperationAs(I)) {
662 if (!J->isSameOperationAs(I, Instruction::CompareIgnoringAlignment))
684663 return false;
685 }
664
686665 // FIXME: handle addsub-type operations!
687666
688667 if (IsSimpleLoadStore) {
239239 // isSameOperationAs
240240 // This should be kept in sync with isEquivalentOperation in
241241 // lib/Transforms/IPO/MergeFunctions.cpp.
242 bool Instruction::isSameOperationAs(const Instruction *I) const {
242 bool Instruction::isSameOperationAs(const Instruction *I,
243 unsigned flags) const {
244 bool IgnoreAlignment = flags & CompareIgnoringAlignment;
245 bool UseScalarTypes = flags & CompareUsingScalarTypes;
246
243247 if (getOpcode() != I->getOpcode() ||
244248 getNumOperands() != I->getNumOperands() ||
245 getType() != I->getType())
249 (UseScalarTypes ?
250 getType()->getScalarType() != I->getType()->getScalarType() :
251 getType() != I->getType()))
246252 return false;
247253
248254 // We have two instructions of identical opcode and #operands. Check to see
249255 // if all operands are the same type
250256 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
251 if (getOperand(i)->getType() != I->getOperand(i)->getType())
257 if (UseScalarTypes ?
258 getOperand(i)->getType()->getScalarType() !=
259 I->getOperand(i)->getType()->getScalarType() :
260 getOperand(i)->getType() != I->getOperand(i)->getType())
252261 return false;
253262
254263 // Check special state that is a part of some instructions.
255264 if (const LoadInst *LI = dyn_cast(this))
256265 return LI->isVolatile() == cast(I)->isVolatile() &&
257 LI->getAlignment() == cast(I)->getAlignment() &&
266 (LI->getAlignment() == cast(I)->getAlignment() ||
267 IgnoreAlignment) &&
258268 LI->getOrdering() == cast(I)->getOrdering() &&
259269 LI->getSynchScope() == cast(I)->getSynchScope();
260270 if (const StoreInst *SI = dyn_cast(this))
261271 return SI->isVolatile() == cast(I)->isVolatile() &&
262 SI->getAlignment() == cast(I)->getAlignment() &&
272 (SI->getAlignment() == cast(I)->getAlignment() ||
273 IgnoreAlignment) &&
263274 SI->getOrdering() == cast(I)->getOrdering() &&
264275 SI->getSynchScope() == cast(I)->getSynchScope();
265276 if (const CmpInst *CI = dyn_cast(this))