teach libanalysis to fold int and fp loads from almost arbitrary
authorChris Lattner <sabre@nondot.org>
Fri, 23 Oct 2009 06:23:49 +0000 (06:23 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 23 Oct 2009 06:23:49 +0000 (06:23 +0000)
commitfe8c7c807c6f815561bc2bdddfd330b05dbdfc93
tree986b56b3b40bc87861e994e74d88a6428def281e
parentf08803b889524454577fcb4b4cd9f900203ab54f
teach libanalysis to fold int and fp loads from almost arbitrary
non-type-safe constant initializers.  This sort of thing happens
quite a bit for 4-byte loads out of string constants, unions,
bitfields, and an interesting endianness check from sqlite, which
is something like this:

const int sqlite3one = 1;
# define SQLITE_BIGENDIAN    (*(char *)(&sqlite3one)==0)
# define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
# define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)

all of these macros now constant fold away.

This implements PR3152 and is based on a patch started by Eli, but heavily
modified and extended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84936 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/ConstantFolding.cpp
test/Transforms/ConstProp/loads.ll [new file with mode: 0644]