[PATCH] D64886: [Use] Preserve original uselist order in Use::swap().
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 17 14:31:38 PDT 2019
fhahn created this revision.
fhahn added reviewers: efriedma, rnk, dblaikie, reames.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
fhahn added a child revision: D64884: [PHINode] Preserve use-list order when removing incoming values..
There is no need to remove and add the swapped values to their
respective use lists. We can just adjust thread the swapped values in
the uselist, preserving the original order.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D64886
Files:
llvm/include/llvm/IR/Value.h
llvm/lib/IR/Use.cpp
llvm/test/Transforms/LoopReroll/nonconst_lb.ll
Index: llvm/test/Transforms/LoopReroll/nonconst_lb.ll
===================================================================
--- llvm/test/Transforms/LoopReroll/nonconst_lb.ll
+++ llvm/test/Transforms/LoopReroll/nonconst_lb.ll
@@ -56,7 +56,7 @@
; CHECK: %4 = add i32 %3, 3
; CHECK: br label %for.body
-; CHECK: for.body: ; preds = %for.body, %for.body.preheader
+; CHECK: for.body: ; preds = %for.body.preheader, %for.body
; CHECK: %indvar = phi i32 [ 0, %for.body.preheader ], [ %indvar.next, %for.body ]
; CHECK: %5 = add i32 %m, %indvar
; CHECK: %arrayidx = getelementptr inbounds i32, i32* %B, i32 %5
Index: llvm/lib/IR/Use.cpp
===================================================================
--- llvm/lib/IR/Use.cpp
+++ llvm/lib/IR/Use.cpp
@@ -17,21 +17,39 @@
if (Val == RHS.Val)
return;
- if (Val)
- removeFromList();
+ assert(Val && RHS.Val);
Value *OldVal = Val;
+ Use **OldPrev = Prev.getPointer();
+ Use *OldNext = Next;
if (RHS.Val) {
- RHS.removeFromList();
Val = RHS.Val;
- Val->addUse(*this);
+ Prev.setPointer(RHS.Prev.getPointer());
+ Next = RHS.Next;
+
+ // Adjust use list pointers to point to this instead of RHS.
+ if (Next)
+ Next->setPrev(&Next);
+ if (Val->UseList == &RHS)
+ Val->UseList = this;
+ else
+ (*Prev.getPointer()) = this;
} else {
Val = nullptr;
}
if (OldVal) {
RHS.Val = OldVal;
- RHS.Val->addUse(RHS);
+ RHS.Prev.setPointer(OldPrev);
+ RHS.Next = OldNext;
+
+ // Adjust use list pointers to point to RHS instead of this.
+ if (RHS.Next)
+ RHS.Next->setPrev(&RHS.Next);
+ if (RHS.Val->UseList == this)
+ RHS.Val->UseList = &RHS;
+ else
+ (*RHS.Prev.getPointer()) = &RHS;
} else {
RHS.Val = nullptr;
}
Index: llvm/include/llvm/IR/Value.h
===================================================================
--- llvm/include/llvm/IR/Value.h
+++ llvm/include/llvm/IR/Value.h
@@ -77,6 +77,7 @@
friend class ValueAsMetadata; // Allow access to IsUsedByMD.
friend class ValueHandleBase;
+ friend class Use;
const unsigned char SubclassID; // Subclass identifier (for isa/dyn_cast)
unsigned char HasValueHandle : 1; // Has a ValueHandle pointing to this?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64886.210421.patch
Type: text/x-patch
Size: 2337 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190717/44d42081/attachment-0001.bin>
More information about the llvm-commits
mailing list