[PATCH] D44542: [LICM/mustexec] Extend first iteration must exexute logic to fcmps

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 16 09:36:21 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL327722: [LICM/mustexec] Extend first iteration must execute logic to fcmps (authored by reames, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44542?vs=138628&id=138727#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44542

Files:
  llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp
  llvm/trunk/test/Transforms/LICM/hoist-mustexec.ll


Index: llvm/trunk/test/Transforms/LICM/hoist-mustexec.ll
===================================================================
--- llvm/trunk/test/Transforms/LICM/hoist-mustexec.ll
+++ llvm/trunk/test/Transforms/LICM/hoist-mustexec.ll
@@ -33,6 +33,34 @@
   ret i32 -1
 }
 
+; Same as test1, but with a floating point IR and fcmp
+define i32 @test_fcmp(i32* noalias nocapture readonly %a) nounwind uwtable {
+; CHECK-LABEL: @test_fcmp(
+entry:
+; CHECK: %i1 = load i32, i32* %a, align 4
+; CHECK-NEXT: br label %for.body
+  br label %for.body
+
+for.body:
+  %iv = phi float [ 0.0, %entry ], [ %inc, %continue ]
+  %acc = phi i32 [ 0, %entry ], [ %add, %continue ]
+  %r.chk = fcmp olt float %iv, 2000.0
+  br i1 %r.chk, label %continue, label %fail
+continue:
+  %i1 = load i32, i32* %a, align 4
+  %add = add nsw i32 %i1, %acc
+  %inc = fadd float %iv, 1.0
+  %exitcond = fcmp ogt float %inc, 1000.0
+  br i1 %exitcond, label %for.cond.cleanup, label %for.body
+
+for.cond.cleanup:
+  ret i32 %add
+
+fail:
+  call void @f()
+  ret i32 -1
+}
+
 ; Count down from a.length w/entry guard
 ; TODO: currently unable to prove the following:
 ; ule i32 (add nsw i32 %len, -1), %len where len is [0, 512]
Index: llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp
+++ llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp
@@ -1530,23 +1530,22 @@
   auto *BI = dyn_cast<BranchInst>(CondExitBlock->getTerminator());
   if (!BI || !BI->isConditional())
     return false;
-  // todo: handle fcmp someday
+  auto *Cond = dyn_cast<CmpInst>(BI->getCondition());
+  if (!Cond)
+    return false;
   // todo: this would be a lot more powerful if we used scev, but all the
   // plumbing is currently missing to pass a pointer in from the pass
-  auto *ICI = dyn_cast<ICmpInst>(BI->getCondition());
-  if (!ICI)
-    return false;
   // Check for cmp (phi [x, preheader] ...), y where (pred x, y is known
-  auto *LHS = dyn_cast<PHINode>(ICI->getOperand(0));
-  auto *RHS = ICI->getOperand(1);
+  auto *LHS = dyn_cast<PHINode>(Cond->getOperand(0));
+  auto *RHS = Cond->getOperand(1);
   if (!LHS || LHS->getParent() != CurLoop->getHeader())
     return false;
   auto DL = ExitBlock->getModule()->getDataLayout();
   auto *IVStart = LHS->getIncomingValueForBlock(CurLoop->getLoopPreheader());
-  auto *SimpleValOrNull = SimplifyICmpInst(ICI->getPredicate(),
-                                           IVStart, RHS,
-                                           {DL, /*TLI*/ nullptr,
-                                               DT, /*AC*/ nullptr, BI});
+  auto *SimpleValOrNull = SimplifyCmpInst(Cond->getPredicate(),
+                                          IVStart, RHS,
+                                          {DL, /*TLI*/ nullptr,
+                                              DT, /*AC*/ nullptr, BI});
   auto *SimpleCst = dyn_cast_or_null<Constant>(SimpleValOrNull);
   if (!SimpleCst)
     return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44542.138727.patch
Type: text/x-patch
Size: 3008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180316/1a35809a/attachment.bin>


More information about the llvm-commits mailing list