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

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 25 01:40:33 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()))
----------------
fhahn wrote:

`CondI` must have type i1 here as it is used as condition of the branch, so no check should be necessary?

Maybe simpler to have


```
auto * CondI = dyn_cast<Instruction>(TI->getCondition());
if (!CondI || !isa<CmpInst, TruncInst>(CondI))
  return {}
```

Would be good to also document the restriction to compares & truncs. Perhaps it  would be best to remove the restriction if there is no strong reason to retain it?

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


More information about the llvm-commits mailing list