instcombine: Don't replace all uses for instructions with no uses
authorMeador Inge <meadori@codesourcery.com>
Tue, 27 Nov 2012 18:52:49 +0000 (18:52 +0000)
committerMeador Inge <meadori@codesourcery.com>
Tue, 27 Nov 2012 18:52:49 +0000 (18:52 +0000)
commita241b58f8d5d71eebfb2cb9be3689fe72b454474
tree624e1d36dcd27498d68d57241bba24d80ccf6f9d
parent9e3c3886d0b42b80f9eb38067fa85d96c75a4ec5
instcombine: Don't replace all uses for instructions with no uses

My commit to migrate the printf simplifiers from the simplify-libcalls
in r168604 introduced a regression reported by Duncan [1].  The problem
is that in some cases the library call simplifier can return a new value
that has no uses and the new value's type is different than the old value's
type (which is fine because there are no uses).  The specific case that
triggered the bug looked something like:

   declare void @printf(i8*, ...)
   ...
   call void (i8*, ...)* @printf(i8* %fmt)

Which we want to optimized into:

   call i32 @putchar(i32 104)

However, the code was attempting to replace all uses of the printf with
the putchar and the types differ, hence a crash.  This is fixed by *just*
deleting the original instruction when there are no uses.  The old
simplify-libcalls pass is already doing something similar.

[1] http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-November/056338.html

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168716 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineCalls.cpp
test/Transforms/InstCombine/printf-2.ll [new file with mode: 0644]