llvm-6502/lib/Transforms/Scalar
Chris Lattner 1f12e44b62 Teach instcombine to fold compares of loads from constant
arrays with variable indices into a comparison of the index
with a constant.  The most common occurrence of this that
I see by far is stuff like:

if ("foobar"[i] == '\0') ...

which we compile into: if (i == 6), saving a load and 
materialization of the global address.  This also exposes 
loop trip count information to later passes in many cases.

This triggers hundreds of times in xalancbmk, which is where I first
noticed it, but it also triggers in many other apps.  Here are a few 
interesting ones from various apps:

@must_be_connected_without = internal constant [8 x i8*] [i8* getelementptr inbounds ([3 x i8]* @.str64320, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8]* @.str27283, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8]* @.str71327, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8]* @.str72328, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8]* @.str18274, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8]* @.str11267, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8]* @.str32288, i64 0, i64 0), i8* null], align 32 ; <[8 x i8*]*> [#uses=2]
  %scevgep.i = getelementptr [8 x i8*]* @must_be_connected_without, i64 0, i64 %indvar.i ; <i8**> [#uses=1]
  %17 = load ...
  %18 = icmp eq i8* %17, null                     ; <i1> [#uses=1]
-> icmp eq i64 %indvar.i, 7 


@yytable1095 = internal constant [84 x i8] c"\12\01(\05\06\07\08\09\0A\0B\0C\0D\0E1\0F\10\11266\1D: \10\11,-,0\03'\10\11B6\04\17&\18\1945\05\06\07\08\09\0A\0B\0C\0D\0E\1E\0F\10\11*\1A\1B\1C$3+>#%;<IJ=ADFEGH9KL\00\00\00C", align 32 ; <[84 x i8]*> [#uses=2]
  %57 = getelementptr inbounds [84 x i8]* @yytable1095, i64 0, i64 %56 ; <i8*> [#uses=1]
   %mode.0.in = getelementptr inbounds [9 x i32]* @mb_mode_table, i64 0, i64 %.pn ; <i32*> [#uses=1]
load ...
   %64 = icmp eq i8 %58, 4                         ; <i1> [#uses=1]
-> icmp eq i64 %.pn, 35             ; <i1> [#uses=0]


@gsm_DLB = internal constant [4 x i16] [i16 6554, i16 16384, i16 26214, i16 32767]
%scevgep.i = getelementptr [4 x i16]* @gsm_DLB, i64 0, i64 %indvar.i ; <i16*> [#uses=1]
%425 = load %scevgep.i
%426 = icmp eq i16 %425, -32768                 ; <i1> [#uses=0]
-> false



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92411 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-02 08:12:04 +00:00
..
ABCD.cpp
ADCE.cpp
BasicBlockPlacement.cpp
CMakeLists.txt
CodeGenPrepare.cpp Revert 91280-91283, 91286-91289, 91291, 91293, 91295-91296. It apparently introduced a non-deterministic behavior in the optimizer somewhere. 2009-12-17 09:39:49 +00:00
ConstantProp.cpp
DCE.cpp
DeadStoreElimination.cpp
GEPSplitter.cpp
GVN.cpp split code that doesn't need to be templated out of IRBuilder into a new 2009-12-28 21:28:46 +00:00
IndVarSimplify.cpp Add Loop contains utility methods for testing whether a loop 2009-12-18 01:24:09 +00:00
InstructionCombining.cpp Teach instcombine to fold compares of loads from constant 2010-01-02 08:12:04 +00:00
JumpThreading.cpp Metadata.h doesn't need to include ValueHandle.h anymore. 2009-12-28 08:20:46 +00:00
LICM.cpp Add Loop contains utility methods for testing whether a loop 2009-12-18 01:24:09 +00:00
LoopDeletion.cpp
LoopIndexSplit.cpp Add Loop contains utility methods for testing whether a loop 2009-12-18 01:24:09 +00:00
LoopRotation.cpp
LoopStrengthReduce.cpp Remove dump routine and the associated Debug.h from a header. Patch up 2009-12-23 22:58:38 +00:00
LoopUnrollPass.cpp
LoopUnswitch.cpp Add Loop contains utility methods for testing whether a loop 2009-12-18 01:24:09 +00:00
Makefile
MemCpyOptimizer.cpp
Reassociate.cpp When factoring multiply expressions across adds, factor both 2010-01-01 01:13:15 +00:00
Reg2Mem.cpp
Scalar.cpp
ScalarReplAggregates.cpp Fix the Convert to scalar to not insert dead loads in the store case. The 2009-12-22 19:33:28 +00:00
SCCP.cpp
SCCVN.cpp Eliminte unnecessary uses of <cstdio>. 2009-12-18 03:25:51 +00:00
SimplifyCFGPass.cpp Implement PR5795 by merging duplicated return blocks. This could go further 2009-12-22 06:07:30 +00:00
SimplifyHalfPowrLibCalls.cpp improve portability to avoid conflicting with std::next in c++'0x. 2009-12-03 00:50:42 +00:00
SimplifyLibCalls.cpp move an optimization for memcmp out of simplifylibcalls and into 2009-12-24 00:37:38 +00:00
TailDuplication.cpp
TailRecursionElimination.cpp