[PATCH] D16831: [regalloc][WinEH] Do not mark intervals as not spillable if they contain a regmask

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 3 17:58:18 PST 2016

MatzeB added inline comments.

Comment at: lib/CodeGen/LiveInterval.cpp:757-762
@@ +756,8 @@
+    return false;
+  // Otherwise, see if any regmask is contained by any of our segments.
+  for (const Segment &S : segments) {
+    // Find the first regmask slot at or after this segment start.
+    while (*SlotI < S.start)
+      if (++SlotI == SlotE)
+        return false;
+    // If the segment contains this slot, we have our answer.
andrew.w.kaylor wrote:
> MatzeB wrote:
> > This does not need to be a quadratic algorithm as the regmaskslots and segments are both sorted!
> > 
> > I'd initialize an iterator with segments.begin(), loop over the RegMaskSlots and use advanceTo() to check each index.
> I don't think this is quadratic the way I've implemented it.  The inner while loop just advances the slot iterator from wherever it was (at the start of the current for loop iteration) to the first slot that is at or after the start of the current segment.  This will never visit any slot from RegMaskSlots or any segment more than once.
> I think that what you are suggesting would accomplish the same thing, just switching the hierarchy of the two loops and using advanceTo in place of the inner loop.  I'm happy to do it that way if you think it reads better.  I admit that the way I have written this code it does look quadratic.
You are right your code is not quadratic. It would still be nice to rewrite it using advanceTo() maybe also using find(RegMaskSlots.front()) to initialize the iterator as that uses a binary search algorithm.



More information about the llvm-commits mailing list