[llvm] [LoopUnswitch] Allow i1 truncs in loop unswitch (PR #89738)

Matthew Devereau via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 25 06:10:57 PDT 2024


================
@@ -1930,7 +1930,13 @@ llvm::hasPartialIVCondition(const Loop &L, unsigned MSSAThreshold,
   if (!TI || !TI->isConditional())
     return {};
 
-  auto *CondI = dyn_cast<CmpInst>(TI->getCondition());
+  Instruction *CondI = dyn_cast<CmpInst>(TI->getCondition());
+  if (!CondI) {
+    CondI = dyn_cast<TruncInst>(TI->getCondition());
+    if (CondI && CondI->getType() != Type::getInt1Ty(TI->getContext()))
----------------
MDevereau wrote:

You've got a good point that it may be best to remove the restrictions, but I removed them and they broke quite a few tests, such as nested cases which shouldn't be unswitched and cases with phi nodes as the condition. Given this patch is a response to a specific regression I'd prefer to keep it simple if that's alright.

As for the CondI suggestion I've put that in and it looks cleaner - thanks. I've also added a short comment above to describe why it's just limited to Cmp and Trunc

https://github.com/llvm/llvm-project/pull/89738


More information about the llvm-commits mailing list