improve codegen for variables that are assigned but never used. (ref #9343)

this builds and passes tests with LLVM assertions, but we should be
on the lookout for regressions here.