From 0c0f7c935bc4c6de74bd4025ceca7278e128f48d Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Mon, 10 Sep 2007 23:34:06 +0000 Subject: [PATCH] Swap exit condition operands if it works. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41817 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopIndexSplit.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp index 3a046655d5e..0f55a9100c3 100644 --- a/lib/Transforms/Scalar/LoopIndexSplit.cpp +++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp @@ -328,14 +328,24 @@ void LoopIndexSplit::findLoopConditionals() { if (!CI) return; - // FIXME + // FIXME + if (CI->getPredicate() == ICmpInst::ICMP_EQ + || CI->getPredicate() == ICmpInst::ICMP_NE) + return; + if (CI->getPredicate() == ICmpInst::ICMP_SGT || CI->getPredicate() == ICmpInst::ICMP_UGT || CI->getPredicate() == ICmpInst::ICMP_SGE - || CI->getPredicate() == ICmpInst::ICMP_UGE - || CI->getPredicate() == ICmpInst::ICMP_EQ - || CI->getPredicate() == ICmpInst::ICMP_NE) - return; + || CI->getPredicate() == ICmpInst::ICMP_UGE) { + + BasicBlock *FirstSuccessor = BR->getSuccessor(0); + // splitLoop() is expecting LT/LE as exit condition predicate. + // Swap operands here if possible to meet this requirement. + if (!L->contains(FirstSuccessor)) + CI->swapOperands(); + else + return; + } ExitCondition = CI;