From 22cfa14eed3b65445e14105a16bd9512e142e7d9 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 15 Dec 2008 03:46:38 +0000 Subject: [PATCH] make GVN try to rename inputs to the resultant replaced values, which cleans up the generated code a bit. This should have the added benefit of not randomly renaming functions/globals like my previous patch did. :) llvm-svn: 61023 --- lib/Transforms/Scalar/GVN.cpp | 6 +++++- test/Transforms/GVN/2007-07-26-InterlockingLoops.ll | 4 ++-- test/Transforms/GVN/2007-07-26-PhiErasure.ll | 2 +- test/Transforms/GVN/2007-07-31-NoDomInherit.ll | 2 +- test/Transforms/GVN/rle-dominated.ll | 8 ++++---- test/Transforms/GVN/rle-must-alias.ll | 2 +- test/Transforms/GVN/rle-nonlocal.ll | 2 +- test/Transforms/GVN/rle-phi-translate.ll | 4 ++-- test/Transforms/GVN/rle-semidominated.ll | 2 +- 9 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index 8cfc62768f6..d3e15d457a4 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -1040,6 +1040,9 @@ bool GVN::processNonLocalLoad(LoadInst *LI, // Perform PHI construction. Value* v = GetValueForBlock(LI->getParent(), LI, BlockReplValues, true); LI->replaceAllUsesWith(v); + + if (!isa(v)) + v->takeName(LI); if (isa(v->getType())) MD->invalidateCachedPointerInfo(v); toErase.push_back(LI); @@ -1135,7 +1138,8 @@ bool GVN::processNonLocalLoad(LoadInst *LI, // Perform PHI construction. Value* v = GetValueForBlock(LI->getParent(), LI, BlockReplValues, true); LI->replaceAllUsesWith(v); - v->takeName(LI); + if (!isa(v)) + v->takeName(LI); if (isa(v->getType())) MD->invalidateCachedPointerInfo(v); toErase.push_back(LI); diff --git a/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll b/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll index 1dd1479b482..5403a1bdb5e 100644 --- a/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll +++ b/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll @@ -1,5 +1,5 @@ -; RUN: llvm-as < %s | opt -gvn | llvm-dis | not grep {tmp17625 =} -; RUN: llvm-as < %s | opt -gvn | llvm-dis | not grep {tmp17631 =} +; RUN: llvm-as < %s | opt -gvn | llvm-dis | grep {tmp17625 = phi i32. } +; RUN: llvm-as < %s | opt -gvn | llvm-dis | grep {tmp17631.* = phi i32. } @last = external global [65 x i32*] ; <[65 x i32*]*> [#uses=1] diff --git a/test/Transforms/GVN/2007-07-26-PhiErasure.ll b/test/Transforms/GVN/2007-07-26-PhiErasure.ll index 52c5b8e7ec8..4925df786d7 100644 --- a/test/Transforms/GVN/2007-07-26-PhiErasure.ll +++ b/test/Transforms/GVN/2007-07-26-PhiErasure.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | opt -gvn | llvm-dis | not grep {tmp298316 =} +; RUN: llvm-as < %s | opt -gvn | llvm-dis | grep {tmp298316 = phi i32 } %struct..0anon = type { i32 } %struct.FILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, %struct.__sFILEX*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64 } diff --git a/test/Transforms/GVN/2007-07-31-NoDomInherit.ll b/test/Transforms/GVN/2007-07-31-NoDomInherit.ll index 5dbd34c0cde..6cb7785fcd5 100644 --- a/test/Transforms/GVN/2007-07-31-NoDomInherit.ll +++ b/test/Transforms/GVN/2007-07-31-NoDomInherit.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | opt -gvn | llvm-dis | grep tmp51.rle +; RUN: llvm-as < %s | opt -gvn | llvm-dis | grep {tmp47 = phi i32 } %struct.anon = type { i32 (i32, i32, i32)*, i32, i32, [3 x i32], i8*, i8*, i8* } @debug = external constant i32 ; [#uses=0] diff --git a/test/Transforms/GVN/rle-dominated.ll b/test/Transforms/GVN/rle-dominated.ll index d7c9417bcf7..0d517178675 100644 --- a/test/Transforms/GVN/rle-dominated.ll +++ b/test/Transforms/GVN/rle-dominated.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | opt -gvn | llvm-dis | not grep DEAD +; RUN: llvm-as < %s | opt -gvn | llvm-dis | grep load | count 2 define i32 @main(i32** %p) { block1: @@ -14,7 +14,7 @@ block3: br label %block4 block4: - %DEAD = load i32** %p - %c = load i32* %DEAD - ret i32 %c + %c = load i32** %p + %d = load i32* %c + ret i32 %d } diff --git a/test/Transforms/GVN/rle-must-alias.ll b/test/Transforms/GVN/rle-must-alias.ll index 7108916d277..ada43985718 100644 --- a/test/Transforms/GVN/rle-must-alias.ll +++ b/test/Transforms/GVN/rle-must-alias.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | opt -gvn | llvm-dis | grep {DEAD.rle = phi i32} +; RUN: llvm-as < %s | opt -gvn | llvm-dis | grep {DEAD = phi i32 } ; XFAIL: * ; FIXME: GVN should eliminate the fully redundant %9 GEP which diff --git a/test/Transforms/GVN/rle-nonlocal.ll b/test/Transforms/GVN/rle-nonlocal.ll index 1618d05efb5..d93223131d7 100644 --- a/test/Transforms/GVN/rle-nonlocal.ll +++ b/test/Transforms/GVN/rle-nonlocal.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | opt -gvn | llvm-dis | not grep {DEAD =} +; RUN: llvm-as < %s | opt -gvn | llvm-dis | grep {%DEAD = phi i32. } define i32 @main(i32** %p) { block1: diff --git a/test/Transforms/GVN/rle-phi-translate.ll b/test/Transforms/GVN/rle-phi-translate.ll index 0f9c58ffac8..b5311eec59c 100644 --- a/test/Transforms/GVN/rle-phi-translate.ll +++ b/test/Transforms/GVN/rle-phi-translate.ll @@ -1,5 +1,5 @@ -; RUN: llvm-as < %s | opt -gvn | llvm-dis | grep {%cv.rle = phi i32} -; RUN: llvm-as < %s | opt -gvn | llvm-dis | grep {%bv.rle = phi i32} +; RUN: llvm-as < %s | opt -gvn | llvm-dis | grep {%cv = phi i32} +; RUN: llvm-as < %s | opt -gvn | llvm-dis | grep {%bv = phi i32} target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" target triple = "i386-apple-darwin7" diff --git a/test/Transforms/GVN/rle-semidominated.ll b/test/Transforms/GVN/rle-semidominated.ll index 95ee56a39c0..5c11b06e732 100644 --- a/test/Transforms/GVN/rle-semidominated.ll +++ b/test/Transforms/GVN/rle-semidominated.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | opt -gvn | llvm-dis | not grep {DEAD =} +; RUN: llvm-as < %s | opt -gvn | llvm-dis | grep {DEAD = phi i32 } define i32 @main(i32* %p) { block1: