forked from OSchip/llvm-project
[BasicAA] Handle known non-zero variable index
BasicAA currently handles cases like Scale*V0 + (-Scale)*V1 where V0 != V1, but does not handle the simpler case of Scale*V with V != 0. Add it based on an isKnownNonZero() call. I'm not passing a context instruction for now, because the existing approach of always using GEP1 for context could result in symmetry issues. Differential Revision: https://reviews.llvm.org/D93162
This commit is contained in:
parent
05d1729232
commit
bb939ebfd7
|
@ -1288,8 +1288,12 @@ AliasResult BasicAAResult::aliasGEP(
|
|||
if (V1Size.hasValue() && V2Size.hasValue()) {
|
||||
// Try to determine whether abs(VarIndex) > 0.
|
||||
Optional<APInt> MinAbsVarIndex;
|
||||
// TODO: Could handle single non-zero index as well.
|
||||
if (DecompGEP1.VarIndices.size() == 2) {
|
||||
if (DecompGEP1.VarIndices.size() == 1) {
|
||||
// VarIndex = Scale*V. If V != 0 then abs(VarIndex) >= abs(Scale).
|
||||
const VariableGEPIndex &Var = DecompGEP1.VarIndices[0];
|
||||
if (isKnownNonZero(Var.V, DL))
|
||||
MinAbsVarIndex = Var.Scale.abs();
|
||||
} else if (DecompGEP1.VarIndices.size() == 2) {
|
||||
// VarIndex = Scale*V0 + (-Scale)*V1.
|
||||
// If V0 != V1 then abs(VarIndex) >= abs(Scale).
|
||||
// Check that VisitedPhiBBs is empty, to avoid reasoning about
|
||||
|
|
|
@ -4,9 +4,9 @@ target triple = "x86_64-apple-darwin13.4.0"
|
|||
|
||||
; CHECK-LABEL: compute1
|
||||
; CHECK: MayAlias: i32* %arrayidx8, i32* %out
|
||||
; CHECK: MayAlias: i32* %arrayidx11, i32* %out
|
||||
; CHECK: NoAlias: i32* %arrayidx11, i32* %out
|
||||
; CHECK: MayAlias: i32* %arrayidx11, i32* %arrayidx8
|
||||
; CHECK: MayAlias: i32* %arrayidx14, i32* %out
|
||||
; CHECK: NoAlias: i32* %arrayidx14, i32* %out
|
||||
; CHECK: MayAlias: i32* %arrayidx14, i32* %arrayidx8
|
||||
; CHECK: MayAlias: i32* %arrayidx11, i32* %arrayidx14
|
||||
define void @compute1(i32 %num.0.lcssa, i32* %out) {
|
||||
|
|
|
@ -111,10 +111,9 @@ define void @add_non_zero_with_offset(i32* %p, i32 %addend, i32* %q) {
|
|||
}
|
||||
|
||||
; CHECK-LABEL: non_zero_index_simple
|
||||
; CHECK: MayAlias: i32* %gep, i32* %p
|
||||
; CHECK: MayAlias: i16* %gep.16, i32* %p
|
||||
; CHECK: NoAlias: i32* %gep, i32* %p
|
||||
; CHECK: NoAlias: i16* %gep.16, i32* %p
|
||||
; CHECK: MayAlias: i32* %p, i64* %gep.64
|
||||
; TODO: First two could be NoAlias.
|
||||
define void @non_zero_index_simple(i32* %p, i32* %q) {
|
||||
%knownnonzero = load i32, i32* %q, !range !0
|
||||
%gep = getelementptr i32, i32* %p, i32 %knownnonzero
|
||||
|
@ -125,8 +124,7 @@ define void @non_zero_index_simple(i32* %p, i32* %q) {
|
|||
|
||||
; CHECK-LABEL: non_zero_index_with_offset
|
||||
; CHECK: MayAlias: i32* %gep, i32* %p
|
||||
; CHECK: MayAlias: i16* %gep.16, i32* %p
|
||||
; TODO: Last could be NoAlias.
|
||||
; CHECK: NoAlias: i16* %gep.16, i32* %p
|
||||
define void @non_zero_index_with_offset(i32* %p, i32* %q) {
|
||||
%knownnonzero = load i32, i32* %q, !range !0
|
||||
%p.8 = bitcast i32* %p to i8*
|
||||
|
|
Loading…
Reference in New Issue