Fix a bug in just submitted rL369789
Started implementing the vector case and realized the scalar case hadn't handled the GEP producing a different type than the base correctly. It's entertaining seeing what slips through review when we're focused on the 'hard' parts. :( Also adding an extra vector test as it happened to be in workspace and wasn't worth separating. llvm-svn: 369795
This commit is contained in:
parent
2fd1afe8ef
commit
9cb059fdcc
@ -914,7 +914,10 @@ Instruction *InstCombiner::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
|
||||
// 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
|
||||
// non-poison cases (1 and 4 above).
|
||||
return new ICmpInst(Cond, GEPLHS->getPointerOperand(), RHS);
|
||||
auto *Base = GEPLHS->getPointerOperand();
|
||||
return new ICmpInst(Cond, Base,
|
||||
ConstantExpr::getBitCast(cast<Constant>(RHS),
|
||||
Base->getType()));
|
||||
} else if (GEPOperator *GEPRHS = dyn_cast<GEPOperator>(RHS)) {
|
||||
// If the base pointers are different, but the indices are the same, just
|
||||
// compare the base pointer.
|
||||
|
||||
@ -102,6 +102,19 @@ entry:
|
||||
ret <2 x i1> %cnd
|
||||
}
|
||||
|
||||
define <2 x i1> @test_vector_both(<2 x i8*> %base, <2 x i64> %idx) {
|
||||
; CHECK-LABEL: @test_vector_both(
|
||||
; 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*> [[GEP]], zeroinitializer
|
||||
; CHECK-NEXT: ret <2 x i1> [[CND]]
|
||||
;
|
||||
entry:
|
||||
%gep = getelementptr inbounds i8, <2 x i8*> %base, <2 x i64> %idx
|
||||
%cnd = icmp eq <2 x i8*> %gep, zeroinitializer
|
||||
ret <2 x i1> %cnd
|
||||
}
|
||||
|
||||
;; These two show instsimplify's reasoning getting to the non-zero offsets
|
||||
;; before instcombine does.
|
||||
|
||||
@ -155,6 +168,19 @@ entry:
|
||||
}
|
||||
|
||||
|
||||
define i1 @test_index_type([10 x i8]* %base, i64 %idx) {
|
||||
; CHECK-LABEL: @test_index_type(
|
||||
; CHECK-NEXT: entry:
|
||||
; CHECK-NEXT: [[CND:%.*]] = icmp eq [10 x i8]* [[BASE:%.*]], null
|
||||
; CHECK-NEXT: ret i1 [[CND]]
|
||||
;
|
||||
entry:
|
||||
%gep = getelementptr inbounds [10 x i8], [10 x i8]* %base, i64 %idx, i64 %idx
|
||||
%cnd = icmp eq i8* %gep, null
|
||||
ret i1 %cnd
|
||||
}
|
||||
|
||||
|
||||
;; Finally, some negative tests for sanity checking.
|
||||
|
||||
define i1 @neq_noinbounds(i8* %base, i64 %idx) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user