[PATCH] D33226: [NewGVN] Replace predicate info leftovers

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Tue May 16 10:30:59 PDT 2017


I realized that after we replace the use we just leave the (dead)
instruction around.
We could let subsequent passes remove it (e.g. DCE), but I'd rather
let NewGVN doing the job.
The following is the most localized way I was able to find to
accomplish the task. What do you think?

diff --git a/lib/Transforms/Scalar/NewGVN.cpp b/lib/Transforms/Scalar/NewGVN.cpp
index 5d76c6e..f9cfe88 100644
--- a/lib/Transforms/Scalar/NewGVN.cpp
+++ b/lib/Transforms/Scalar/NewGVN.cpp
@@ -3315,6 +3315,8 @@ bool NewGVN::eliminateInstructions(Function &F) {
           // It's about to be alive again.
           if (LeaderUseCount == 0 && isa<Instruction>(DominatingLeader))
             ProbablyDead.erase(cast<Instruction>(DominatingLeader));
+          if (LeaderUseCount == 0 && II)
+            ProbablyDead.insert(II);
           ++LeaderUseCount;
           AnythingReplaced = true;
         }


On Mon, May 15, 2017 at 10:36 PM, Davide Italiano via Phabricator via
llvm-commits <llvm-commits at lists.llvm.org> wrote:
> This revision was automatically updated to reflect the committed changes.
> Closed by commit rL303141: [NewGVN] Replace predicate info leftovers. (authored by davide).
>
> Changed prior to commit:
>   https://reviews.llvm.org/D33226?vs=99098&id=99102#toc
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D33226
>
> Files:
>   llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
>   llvm/trunk/test/Transforms/NewGVN/pr32945.ll
>
>
> Index: llvm/trunk/test/Transforms/NewGVN/pr32945.ll
> ===================================================================
> --- llvm/trunk/test/Transforms/NewGVN/pr32945.ll
> +++ llvm/trunk/test/Transforms/NewGVN/pr32945.ll
> @@ -0,0 +1,24 @@
> +; RUN: opt -S -newgvn %s | FileCheck %s
> +; CHECK-NOT: call i32 @llvm.ssa.copy
> +
> + at d = external global i32
> + at e = external global i32
> +define void @tinkywinky() {
> +  br i1 true, label %lor.lhs.false, label %cond.true
> +lor.lhs.false:
> +  %tmp = load i32, i32* @d, align 4
> +  %patatino = load i32, i32* null, align 4
> +  %or = or i32 %tmp, %patatino
> +  store i32 %or, i32* @d, align 4
> +  br label %cond.true
> +cond.true:
> +  %tmp1 = load i32, i32* @e, align 4
> +  %tmp2 = load i32, i32* @d, align 4
> +  %cmp = icmp eq i32 %tmp1, %tmp2
> +  br i1 %cmp, label %cond.true6, label %cond.false
> +cond.true6:
> +  %cmp7 = icmp slt i32 %tmp1, 0
> +  br i1 %cmp7, label %cond.false, label %cond.false
> +cond.false:
> +  ret void
> +}
> Index: llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
> ===================================================================
> --- llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
> +++ llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
> @@ -3291,6 +3291,10 @@
>
>            Value *DominatingLeader = EliminationStack.back();
>
> +          auto *II = dyn_cast<IntrinsicInst>(DominatingLeader);
> +          if (II && II->getIntrinsicID() == Intrinsic::ssa_copy)
> +            DominatingLeader = II->getOperand(0);
> +
>            // Don't replace our existing users with ourselves.
>            if (U->get() == DominatingLeader)
>              continue;
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>

-- 
Davide

"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare


More information about the llvm-commits mailing list