llvm-6502/test/CodeGen/X86/codegen-prepare.ll
Hal Finkel 24517d023f Add the ability to use GEPs for address sinking in CGP
The current memory-instruction optimization logic in CGP, which sinks parts of
the address computation that can be adsorbed by the addressing mode, does this
by explicitly converting the relevant part of the address computation into
IR-level integer operations (making use of ptrtoint and inttoptr). For most
targets this is currently not a problem, but for targets wishing to make use of
IR-level aliasing analysis during CodeGen, the use of ptrtoint/inttoptr is a
problem for two reasons:
  1. BasicAA becomes less powerful in the face of the ptrtoint/inttoptr
  2. In cases where type-punning was used, and BasicAA was used
     to override TBAA, BasicAA may no longer do so. (this had forced us to disable
     all use of TBAA in CodeGen; something which we can now enable again)

This (use of GEPs instead of ptrtoint/inttoptr) is not currently enabled by
default (except for those targets that use AA during CodeGen), and so aside
from some PowerPC subtargets and SystemZ, there should be no change in
behavior. We may be able to switch completely away from the ptrtoint/inttoptr
sinking on all targets, but further testing is required.

I've doubled-up on a number of existing tests that are sensitive to the
address sinking behavior (including some store-merging tests that are
sensitive to the order of the resulting ADD operations at the SDAG level).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206092 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-12 00:59:48 +00:00

46 lines
1.7 KiB
LLVM

; RUN: llc < %s -mtriple=x86_64-pc-linux | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-pc-linux -addr-sink-using-gep=1 | FileCheck %s
; Check that the CodeGenPrepare Pass
; does not wrongly rewrite the address computed by Instruction %4
; as [12 + Base:%this].
; This test makes sure that:
; - both the store and the first load instructions
; within basic block labeled 'if.then' are not removed.
; - the store instruction stores a value at address [60 + %this]
; - the first load instruction loads a value at address [12 + %this]
%class.A = type { %struct.B }
%struct.B = type { %class.C, %class.D, %class.C, %class.D }
%class.C = type { float, float, float }
%class.D = type { [3 x %class.C] }
define linkonce_odr void @foo(%class.A* nocapture %this, i32 %BoolValue) nounwind uwtable {
entry:
%cmp = icmp eq i32 %BoolValue, 0
%address1 = getelementptr inbounds %class.A* %this, i64 0, i32 0, i32 3
%address2 = getelementptr inbounds %class.A* %this, i64 0, i32 0, i32 1
br i1 %cmp, label %if.else, label %if.then
if.then: ; preds = %entry
%0 = getelementptr inbounds %class.D* %address2, i64 0, i32 0, i64 0, i32 0
%1 = load float* %0, align 4
%2 = getelementptr inbounds float* %0, i64 3
%3 = load float* %2, align 4
%4 = getelementptr inbounds %class.D* %address1, i64 0, i32 0, i64 0, i32 0
store float %1, float* %4, align 4
br label %if.end
if.else: ; preds = %entry
br label %if.end
if.end: ; preds = %if.then, %if.else, %entry
ret void
}
; CHECK-LABEL: foo:
; CHECK: movss 12([[THIS:%[a-zA-Z0-9]+]]), [[REGISTER:%[a-zA-Z0-9]+]]
; CHECK-NEXT: movss [[REGISTER]], 60([[THIS]])