forked from OSchip/llvm-project
[InstCombine] icmp eq/ne (gep inbounds P, Idx..), null -> icmp eq/ne P, null for vectors
Extend the transform introduced in https://reviews.llvm.org/D66608 to work for vector geps as well. Differential Revision: https://reviews.llvm.org/D66671 llvm-svn: 369949
This commit is contained in:
parent
7e3d043459
commit
b92c971099
|
@ -895,7 +895,6 @@ Instruction *InstCombiner::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
|
||||||
return new ICmpInst(ICmpInst::getSignedPredicate(Cond), Offset,
|
return new ICmpInst(ICmpInst::getSignedPredicate(Cond), Offset,
|
||||||
Constant::getNullValue(Offset->getType()));
|
Constant::getNullValue(Offset->getType()));
|
||||||
} else if (GEPLHS->isInBounds() && ICmpInst::isEquality(Cond) &&
|
} else if (GEPLHS->isInBounds() && ICmpInst::isEquality(Cond) &&
|
||||||
GEPLHS->getType()->isPointerTy() && // TODO: extend to vector geps
|
|
||||||
isa<Constant>(RHS) && cast<Constant>(RHS)->isNullValue() &&
|
isa<Constant>(RHS) && cast<Constant>(RHS)->isNullValue() &&
|
||||||
!NullPointerIsDefined(I.getFunction(),
|
!NullPointerIsDefined(I.getFunction(),
|
||||||
RHS->getType()->getPointerAddressSpace())) {
|
RHS->getType()->getPointerAddressSpace())) {
|
||||||
|
@ -914,7 +913,13 @@ Instruction *InstCombiner::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
|
||||||
// In general, we're allowed to make values less poison (i.e. remove
|
// In general, we're allowed to make values less poison (i.e. remove
|
||||||
// sources of full UB), so in this case, we just select between the two
|
// sources of full UB), so in this case, we just select between the two
|
||||||
// non-poison cases (1 and 4 above).
|
// non-poison cases (1 and 4 above).
|
||||||
|
//
|
||||||
|
// For vectors, we apply the same reasoning on a per-lane basis.
|
||||||
auto *Base = GEPLHS->getPointerOperand();
|
auto *Base = GEPLHS->getPointerOperand();
|
||||||
|
if (GEPLHS->getType()->isVectorTy() && Base->getType()->isPointerTy()) {
|
||||||
|
int NumElts = GEPLHS->getType()->getVectorNumElements();
|
||||||
|
Base = Builder.CreateVectorSplat(NumElts, Base);
|
||||||
|
}
|
||||||
return new ICmpInst(Cond, Base,
|
return new ICmpInst(Cond, Base,
|
||||||
ConstantExpr::getBitCast(cast<Constant>(RHS),
|
ConstantExpr::getBitCast(cast<Constant>(RHS),
|
||||||
Base->getType()));
|
Base->getType()));
|
||||||
|
|
|
@ -75,12 +75,10 @@ entry:
|
||||||
ret i1 %cnd
|
ret i1 %cnd
|
||||||
}
|
}
|
||||||
|
|
||||||
;; TODO: vectors not yet handled
|
|
||||||
define <2 x i1> @test_vector_base(<2 x i8*> %base, i64 %idx) {
|
define <2 x i1> @test_vector_base(<2 x i8*> %base, i64 %idx) {
|
||||||
; CHECK-LABEL: @test_vector_base(
|
; CHECK-LABEL: @test_vector_base(
|
||||||
; CHECK-NEXT: entry:
|
; CHECK-NEXT: entry:
|
||||||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, <2 x i8*> [[BASE:%.*]], i64 [[IDX:%.*]]
|
; CHECK-NEXT: [[CND:%.*]] = icmp eq <2 x i8*> [[BASE:%.*]], zeroinitializer
|
||||||
; CHECK-NEXT: [[CND:%.*]] = icmp eq <2 x i8*> [[GEP]], zeroinitializer
|
|
||||||
; CHECK-NEXT: ret <2 x i1> [[CND]]
|
; CHECK-NEXT: ret <2 x i1> [[CND]]
|
||||||
;
|
;
|
||||||
entry:
|
entry:
|
||||||
|
@ -92,8 +90,9 @@ entry:
|
||||||
define <2 x i1> @test_vector_index(i8* %base, <2 x i64> %idx) {
|
define <2 x i1> @test_vector_index(i8* %base, <2 x i64> %idx) {
|
||||||
; CHECK-LABEL: @test_vector_index(
|
; CHECK-LABEL: @test_vector_index(
|
||||||
; CHECK-NEXT: entry:
|
; CHECK-NEXT: entry:
|
||||||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, i8* [[BASE:%.*]], <2 x i64> [[IDX:%.*]]
|
; CHECK-NEXT: [[DOTSPLATINSERT:%.*]] = insertelement <2 x i8*> undef, i8* [[BASE:%.*]], i32 0
|
||||||
; CHECK-NEXT: [[CND:%.*]] = icmp eq <2 x i8*> [[GEP]], zeroinitializer
|
; CHECK-NEXT: [[DOTSPLAT:%.*]] = shufflevector <2 x i8*> [[DOTSPLATINSERT]], <2 x i8*> undef, <2 x i32> zeroinitializer
|
||||||
|
; CHECK-NEXT: [[CND:%.*]] = icmp eq <2 x i8*> [[DOTSPLAT]], zeroinitializer
|
||||||
; CHECK-NEXT: ret <2 x i1> [[CND]]
|
; CHECK-NEXT: ret <2 x i1> [[CND]]
|
||||||
;
|
;
|
||||||
entry:
|
entry:
|
||||||
|
@ -105,8 +104,7 @@ entry:
|
||||||
define <2 x i1> @test_vector_both(<2 x i8*> %base, <2 x i64> %idx) {
|
define <2 x i1> @test_vector_both(<2 x i8*> %base, <2 x i64> %idx) {
|
||||||
; CHECK-LABEL: @test_vector_both(
|
; CHECK-LABEL: @test_vector_both(
|
||||||
; CHECK-NEXT: entry:
|
; CHECK-NEXT: entry:
|
||||||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, <2 x i8*> [[BASE:%.*]], <2 x i64> [[IDX:%.*]]
|
; CHECK-NEXT: [[CND:%.*]] = icmp eq <2 x i8*> [[BASE:%.*]], zeroinitializer
|
||||||
; CHECK-NEXT: [[CND:%.*]] = icmp eq <2 x i8*> [[GEP]], zeroinitializer
|
|
||||||
; CHECK-NEXT: ret <2 x i1> [[CND]]
|
; CHECK-NEXT: ret <2 x i1> [[CND]]
|
||||||
;
|
;
|
||||||
entry:
|
entry:
|
||||||
|
|
Loading…
Reference in New Issue