llvm-6502/lib
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
..
Analysis [LoopAccesses] Change LAA:getInfo to return a constant reference 2015-02-19 19:15:21 +00:00
AsmParser IR: Fix MDType fields from unsigned to uint64_t 2015-02-19 23:56:07 +00:00
Bitcode IR: Drop scope from MDTemplateParameter 2015-02-19 00:37:21 +00:00
CodeGen Revert r229944: EH: Prune unreachable resume instructions during Dwarf EH preparation 2015-02-20 02:15:36 +00:00
DebugInfo llvm-pdbdump: Add flags controlling the type of values to dump. 2015-02-15 20:27:53 +00:00
ExecutionEngine Don't deference the section_end() iterator. 2015-02-17 20:07:28 +00:00
Fuzzer [fuzzer] one more experimental search mode: -use_coverage_pairs=1 2015-02-20 03:02:37 +00:00
IR IR: Fix MDType fields from unsigned to uint64_t 2015-02-19 23:56:07 +00:00
IRReader Use ADDITIONAL_HEADER_DIRS in all LLVM CMake projects. 2015-02-11 03:28:02 +00:00
LineEditor Use ADDITIONAL_HEADER_DIRS in all LLVM CMake projects. 2015-02-11 03:28:02 +00:00
Linker Prefer SmallVector::append/insert over push_back loops. 2015-02-17 15:29:18 +00:00
LTO [PM] Remove the old 'PassManager.h' header file at the top level of 2015-02-13 10:01:29 +00:00
MC MC: Allow multiple comma-separated expressions on the .uleb128 directive. 2015-02-19 20:24:04 +00:00
Object Introduce Target::createNullTargetStreamer and use it from IRObjectFile. 2015-02-19 00:45:02 +00:00
Option Prefer SmallVector::append/insert over push_back loops. 2015-02-17 15:29:18 +00:00
ProfileData InstrProf: Don't combine expansion regions with code regions 2015-02-18 19:01:06 +00:00
Support Checking if TARGET_OS_IPHONE is defined isn't good enough for 10.7 and earlier. 2015-02-19 19:50:52 +00:00
TableGen MSVC 2013 does not ICE on this code in the same fashion that MSVC 2012 did; NFC. 2015-02-16 19:33:36 +00:00
Target [x86] Make the new vector shuffle legality test on by default, which 2015-02-20 03:05:47 +00:00
Transforms [InstCombine] Remove unnecessary variable indexing into single-element arrays 2015-02-20 03:05:53 +00:00
CMakeLists.txt Reverting r227452, which adds back the fuzzer library. Now excluding the fuzzer library based on LLVM_USE_SANITIZE_COVERAGE being set or unset. 2015-01-29 16:58:29 +00:00
LLVMBuild.txt
Makefile Move DebugInfo to DebugInfo/DWARF. 2015-01-30 18:07:45 +00:00