[LoopUnswitch] Assert that branch condition is either and/or but not both
authorJuneyoung Lee <aqjune@gmail.com>
Wed, 31 Mar 2021 01:34:46 +0000 (10:34 +0900)
committerJuneyoung Lee <aqjune@gmail.com>
Wed, 31 Mar 2021 01:35:22 +0000 (10:35 +0900)
as suggested at https://reviews.llvm.org/rG5bb38e84d3d0#986321

llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp

index 2e1c0de..d1121ec 100644 (file)
@@ -1995,10 +1995,11 @@ static void unswitchNontrivialInvariants(
   bool Direction = true;
   int ClonedSucc = 0;
   if (!FullUnswitch) {
+    Value *Cond = BI->getCondition();
+    assert((match(Cond, m_LogicalAnd()) ^ match(Cond, m_LogicalOr())) &&
+           "Only `or`, `and`, an `select` instructions can combine "
+           "invariants being unswitched.");
     if (!match(BI->getCondition(), m_LogicalOr())) {
-      assert(match(BI->getCondition(), m_LogicalAnd()) &&
-             "Only `or`, `and`, an `select` instructions can combine "
-             "invariants being unswitched.");
       Direction = false;
       ClonedSucc = 1;
     }