Skip to content

Commit 5e5bda7

Browse files
committed
[IR] Simplify Use::swap. NFCI.
The new implementation makes it clear that there are exactly two conditional stores (after the initial no-op optimization). By contrast the old implementation had seven conditionals, some hidden inside other functions. This commit can change the order of operands in operand lists, hence the tweak to one test case. Differential Revision: https://reviews.llvm.org/D80116
1 parent becaa68 commit 5e5bda7

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

llvm/lib/IR/Use.cpp

+11-18
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,17 @@ void Use::swap(Use &RHS) {
1717
if (Val == RHS.Val)
1818
return;
1919

20-
if (Val)
21-
removeFromList();
22-
23-
Value *OldVal = Val;
24-
if (RHS.Val) {
25-
RHS.removeFromList();
26-
Val = RHS.Val;
27-
Val->addUse(*this);
28-
} else {
29-
Val = nullptr;
30-
}
31-
32-
if (OldVal) {
33-
RHS.Val = OldVal;
34-
RHS.Val->addUse(RHS);
35-
} else {
36-
RHS.Val = nullptr;
37-
}
20+
std::swap(Val, RHS.Val);
21+
std::swap(Next, RHS.Next);
22+
std::swap(Prev, RHS.Prev);
23+
24+
*Prev = this;
25+
if (Next)
26+
Next->Prev = &Next;
27+
28+
*RHS.Prev = &RHS;
29+
if (RHS.Next)
30+
RHS.Next->Prev = &RHS.Next;
3831
}
3932

4033
unsigned Use::getOperandNo() const {

llvm/test/Transforms/LoopReroll/nonconst_lb.ll

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ for.end: ; preds = %for.body, %entry
4848
ret void
4949
}
5050
; CHECK-LABEL: @foo
51-
; CHECK: for.body.preheader: ; preds = %entry
51+
; CHECK: for.body.preheader:
5252
; CHECK: %0 = add i32 %n, -1
5353
; CHECK: %1 = sub i32 %0, %m
5454
; CHECK: %2 = lshr i32 %1, 2
5555
; CHECK: %3 = shl nuw i32 %2, 2
5656
; CHECK: %4 = add i32 %3, 3
5757
; CHECK: br label %for.body
5858

59-
; CHECK: for.body: ; preds = %for.body, %for.body.preheader
59+
; CHECK: for.body:
6060
; CHECK: %indvar = phi i32 [ 0, %for.body.preheader ], [ %indvar.next, %for.body ]
6161
; CHECK: %5 = add i32 %m, %indvar
6262
; CHECK: %arrayidx = getelementptr inbounds i32, i32* %B, i32 %5

0 commit comments

Comments
 (0)