Constant fold ptrtoint + compare with address spaces
llvm-svn: 191699
This commit is contained in:
parent
6ca84e3758
commit
06adecabe7
|
@ -1782,7 +1782,7 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
|
||||||
// Turn icmp (ptrtoint x), (ptrtoint/c) into a compare of the input if the
|
// Turn icmp (ptrtoint x), (ptrtoint/c) into a compare of the input if the
|
||||||
// integer type is the same size as the pointer type.
|
// integer type is the same size as the pointer type.
|
||||||
if (TD && LHSCI->getOpcode() == Instruction::PtrToInt &&
|
if (TD && LHSCI->getOpcode() == Instruction::PtrToInt &&
|
||||||
TD->getPointerSizeInBits() == DestTy->getIntegerBitWidth()) {
|
TD->getPointerTypeSizeInBits(SrcTy) == DestTy->getIntegerBitWidth()) {
|
||||||
Value *RHSOp = 0;
|
Value *RHSOp = 0;
|
||||||
if (Constant *RHSC = dyn_cast<Constant>(ICI.getOperand(1))) {
|
if (Constant *RHSC = dyn_cast<Constant>(ICI.getOperand(1))) {
|
||||||
RHSOp = ConstantExpr::getIntToPtr(RHSC, SrcTy);
|
RHSOp = ConstantExpr::getIntToPtr(RHSC, SrcTy);
|
||||||
|
|
|
@ -27,6 +27,26 @@ define i1 @test2(i8* %a, i8* %b) {
|
||||||
ret i1 %r
|
ret i1 %r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; These casts should be folded away.
|
||||||
|
; CHECK-LABEL: @test2_as2_same_int(
|
||||||
|
; CHECK: icmp eq i8 addrspace(2)* %a, %b
|
||||||
|
define i1 @test2_as2_same_int(i8 addrspace(2)* %a, i8 addrspace(2)* %b) {
|
||||||
|
%tmpa = ptrtoint i8 addrspace(2)* %a to i16
|
||||||
|
%tmpb = ptrtoint i8 addrspace(2)* %b to i16
|
||||||
|
%r = icmp eq i16 %tmpa, %tmpb
|
||||||
|
ret i1 %r
|
||||||
|
}
|
||||||
|
|
||||||
|
; These casts should be folded away.
|
||||||
|
; CHECK-LABEL: @test2_as2_larger(
|
||||||
|
; CHECK: icmp eq i8 addrspace(2)* %a, %b
|
||||||
|
define i1 @test2_as2_larger(i8 addrspace(2)* %a, i8 addrspace(2)* %b) {
|
||||||
|
%tmpa = ptrtoint i8 addrspace(2)* %a to i32
|
||||||
|
%tmpb = ptrtoint i8 addrspace(2)* %b to i32
|
||||||
|
%r = icmp eq i32 %tmpa, %tmpb
|
||||||
|
ret i1 %r
|
||||||
|
}
|
||||||
|
|
||||||
; These casts should also be folded away.
|
; These casts should also be folded away.
|
||||||
; CHECK-LABEL: @test3(
|
; CHECK-LABEL: @test3(
|
||||||
; CHECK: icmp eq i8* %a, @global
|
; CHECK: icmp eq i8* %a, @global
|
||||||
|
|
Loading…
Reference in New Issue