AsmWriter: Write alloca array size explicitly (and -instcombine fixup)
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 13 Mar 2015 19:30:44 +0000 (19:30 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 13 Mar 2015 19:30:44 +0000 (19:30 +0000)
commit95ff656ae0dd9e08f385c52976396382cd775194
tree985ae8867dc0db25fa0e1110e580b6e7b1b0fdbc
parent7c93bfa994471be00ada2f5b312d74362c64fc09
AsmWriter: Write alloca array size explicitly (and -instcombine fixup)

Write the `alloca` array size explicitly when it's non-canonical.
Previously, if the array size was `iX 1` (where X is not 32), the type
would mutate to `i32` when round-tripping through assembly.

The testcase I added fails in `verify-uselistorder` (as well as
`FileCheck`), since the use-lists for `i32 1` and `i64 1` change.
(Manman Ren came across this when running `verify-uselistorder` on some
non-trivial, optimized code as part of PR5680.)

The type mutation started with r104911, which allowed array sizes to be
something other than an `i32`.  Starting with r204945, we
"canonicalized" to `i64` on 64-bit platforms -- and then on every
round-trip through assembly, mutated back to `i32`.

I bundled a fixup for `-instcombine` to avoid r204945 on scalar
allocations.  (There wasn't a clean way to sequence this into two
commits, since the assembly change on its own caused testcase churn, and
the `-instcombine` change can't be tested without the assembly changes.)

An obvious alternative fix -- change `AllocaInst::AllocaInst()`,
`AsmWriter` and `LLParser` to treat `intptr_t` as the canonical type for
scalar allocations -- was rejected out of hand, since this required
teaching them each about the data layout.

A follow-up commit will add an `-instcombine` to canonicalize the scalar
allocation array size to `i32 1` rather than leaving `iX 1` alone.

rdar://problem/20075773

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232200 91177308-0d34-0410-b5e6-96231b3b80d8
lib/IR/AsmWriter.cpp
lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
test/Assembler/alloca-size-one.ll [new file with mode: 0644]
test/Transforms/InstCombine/alloca.ll