From a5a47b7afe63ec5741856dd9445b63959bbdafc3 Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Mon, 18 May 2020 11:08:57 +0100 Subject: [PATCH] [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 --- lib/IR/Use.cpp | 25 ++++++++--------------- test/Transforms/LoopReroll/nonconst_lb.ll | 4 ++-- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/lib/IR/Use.cpp b/lib/IR/Use.cpp index dc0716b8537..99049c0232a 100644 --- a/lib/IR/Use.cpp +++ b/lib/IR/Use.cpp @@ -17,24 +17,17 @@ void Use::swap(Use &RHS) { if (Val == RHS.Val) return; - if (Val) - removeFromList(); + std::swap(Val, RHS.Val); + std::swap(Next, RHS.Next); + std::swap(Prev, RHS.Prev); - Value *OldVal = Val; - if (RHS.Val) { - RHS.removeFromList(); - Val = RHS.Val; - Val->addUse(*this); - } else { - Val = nullptr; - } + *Prev = this; + if (Next) + Next->Prev = &Next; - if (OldVal) { - RHS.Val = OldVal; - RHS.Val->addUse(RHS); - } else { - RHS.Val = nullptr; - } + *RHS.Prev = &RHS; + if (RHS.Next) + RHS.Next->Prev = &RHS.Next; } unsigned Use::getOperandNo() const { diff --git a/test/Transforms/LoopReroll/nonconst_lb.ll b/test/Transforms/LoopReroll/nonconst_lb.ll index 46a5805d637..92d893fabbd 100644 --- a/test/Transforms/LoopReroll/nonconst_lb.ll +++ b/test/Transforms/LoopReroll/nonconst_lb.ll @@ -48,7 +48,7 @@ for.end: ; preds = %for.body, %entry ret void } ; CHECK-LABEL: @foo -; CHECK: for.body.preheader: ; preds = %entry +; CHECK: for.body.preheader: ; CHECK: %0 = add i32 %n, -1 ; CHECK: %1 = sub i32 %0, %m ; CHECK: %2 = lshr i32 %1, 2 @@ -56,7 +56,7 @@ for.end: ; preds = %for.body, %entry ; CHECK: %4 = add i32 %3, 3 ; CHECK: br label %for.body -; CHECK: for.body: ; preds = %for.body, %for.body.preheader +; CHECK: 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