llvm-6502/test/Transforms
Hal Finkel 5ecf528fc2 [InstCombine] Remove unnecessary variable indexing into single-element arrays
This change addresses a deficiency pointed out in PR22629. To copy from the bug
report:

[from the bug report]

Consider this code:

int f(int x) {
  int a[] = {12};
  return a[x];
}

GCC knows to optimize this to

movl     $12, %eax
ret

The code generated by recent Clang at -O3 is:

movslq   %edi, %rax
movl     .L_ZZ1fiE1a(,%rax,4), %eax
retq

.L_ZZ1fiE1a:
  .long    12                      # 0xc

[end from the bug report]

This definitely seems worth fixing. I've also seen this kind of code before (as
the base case of generic vector wrapper templates with one element).

The general idea is to look at the GEP feeding a load or a store, which has
some variable as its first non-zero index, and determine if that index must be
zero (or else an out-of-bounds access would occur). We can do this for allocas
and globals with constant initializers where we know the maximum size of the
underlying object. When we find such a GEP, we create a new one for the memory
access with that first variable index replaced with a constant zero.

Even if we can't eliminate the memory access (and sometimes we can't), it is
still useful because it removes unnecessary indexing calculations.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229959 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-20 03:05:53 +00:00
..
ADCE
AddDiscriminators
AlignmentFromAssumptions
ArgumentPromotion FileCheck-ize a test to make it easier to migrate to typeless pointers 2015-02-15 04:14:00 +00:00
AtomicExpand/ARM
BBVectorize
BDCE [BDCE] Don't forget uses of root instructions seen before the instruction itself 2015-02-18 03:12:28 +00:00
BranchFolding
CodeExtractor
CodeGenPrepare
ConstantHoisting
ConstantMerge
ConstProp Avoid conversion to float when creating ConstantDataArray/ConstantDataVector. 2015-02-19 16:08:20 +00:00
CorrelatedValuePropagation
DeadArgElim DeadArgElim: aggregate Return assessment properly. 2015-02-11 23:13:11 +00:00
DeadStoreElimination
EarlyCSE EarlyCSE: Add check lines for test added in r228760 2015-02-10 23:11:02 +00:00
FunctionAttrs
GCOVProfiling
GlobalDCE
GlobalOpt
GVN Allow PRE to insert no-cost phi nodes 2015-02-03 20:37:08 +00:00
IndVarSimplify
Inline Fix a crash in the assumption cache when inlining indirect function calls 2015-02-12 21:04:22 +00:00
InstCombine [InstCombine] Remove unnecessary variable indexing into single-element arrays 2015-02-20 03:05:53 +00:00
InstMerge Minor fix after 229495. 2015-02-18 08:09:28 +00:00
InstSimplify IR: Properly return nullptr when getAggregateElement is out-of-bounds 2015-02-16 04:02:09 +00:00
Internalize
IPConstantProp
IRCE Teach IRCE to look at branch weights when recognizing range checks 2015-01-27 21:38:12 +00:00
JumpThreading Update a test to make it easier to migrate to untyped pointers 2015-02-15 04:13:58 +00:00
LCSSA Update a test to use FileCheck so it's easier to migrate to future typeless pointer changes 2015-02-15 04:13:57 +00:00
LICM Teach isDereferenceablePointer() to look through bitcast constant expressions. 2015-02-05 09:15:37 +00:00
LoadCombine
LoopDeletion
LoopIdiom
LoopReroll [LoopReroll] Relax some assumptions a little. 2015-02-16 17:02:00 +00:00
LoopRotate LoopRotate: Don't walk the uses of a Constant 2015-01-27 06:21:43 +00:00
LoopSimplify Teach SplitBlockPredecessors how to handle landingpad blocks. 2015-01-28 23:06:47 +00:00
LoopStrengthReduce [ARM] Re-re-apply VLD1/VST1 base-update combine. 2015-02-19 23:52:41 +00:00
LoopUnroll Partial fix for bug 22589 2015-02-18 19:32:25 +00:00
LoopUnswitch
LoopVectorize [x86,sdag] Two interrelated changes to the x86 and sdag code. 2015-02-19 10:36:19 +00:00
LowerAtomic
LowerExpectIntrinsic [PM] Port LowerExpectIntrinsic to the new pass manager. 2015-01-24 11:13:02 +00:00
LowerInvoke
LowerSwitch
Mem2Reg
MemCpyOpt ValueTracking: Make isBytewiseValue simpler and more powerful at the same time. 2015-02-07 19:29:02 +00:00
MergeFunc
MetaRenamer
ObjCARC [objc-arc-contract] We can not move retains over instructions which can not conservatively be proven to not decrement the retain's RCIdentity. 2015-02-20 00:02:49 +00:00
PartiallyInlineLibCalls
PhaseOrdering
PlaceSafepoints Add few simple tests to check statepoint placement for invoke instructions. 2015-02-19 11:39:04 +00:00
PruneEH Fix invalid LLVM IR in PruneEH tests 2015-02-11 02:06:47 +00:00
Reassociate Reassociate: cannot negate a INT_MIN value 2015-02-11 19:54:44 +00:00
Reg2Mem
RewriteStatepointsForGC Adjust enablement of RewriteStatepointsForGC 2015-02-20 02:34:49 +00:00
SampleProfile
Scalarizer
ScalarRepl
SCCP
SeparateConstOffsetFromGEP/NVPTX
SimplifyCFG [CodeGenPrepare] Removed duplicate logic. SimplifyCFG already knows how to speculate calls to cttz/ctlz. 2015-02-13 14:15:48 +00:00
Sink
SLPVectorizer [slp] Fix a nasty bug in the SLP vectorizer that Joerg pointed out. 2015-02-12 02:30:56 +00:00
SROA
StraightLineStrengthReduce Add straight-line strength reduction to LLVM 2015-02-03 19:37:06 +00:00
StripSymbols
StructurizeCFG StructurizeCFG: Use a reverse post-order traversal 2015-02-04 20:49:44 +00:00
TailCallElim
TailDup
Util Correctly combine alias.scope metadata by a union instead of intersecting 2015-02-08 17:07:14 +00:00