Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp =================================================================== --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3408,8 +3408,15 @@ // Turn icmp (ptrtoint x), (ptrtoint/c) into a compare of the input if the // integer type is the same size as the pointer type. + const auto& CompatibleSizes = [&](Type* SrcTy, Type* DestTy) -> bool { + if (isa(SrcTy)) { + SrcTy = cast(SrcTy)->getElementType(); + DestTy = cast(DestTy)->getElementType(); + } + return DL.getPointerTypeSizeInBits(SrcTy) == DestTy->getIntegerBitWidth(); + }; if (LHSCI->getOpcode() == Instruction::PtrToInt && - DL.getPointerTypeSizeInBits(SrcTy) == DestTy->getIntegerBitWidth()) { + CompatibleSizes(SrcTy, DestTy)) { Value *RHSOp = nullptr; if (auto *RHSC = dyn_cast(ICmp.getOperand(1))) { Value *RHSCIOp = RHSC->getOperand(0); Index: llvm/trunk/test/Transforms/InstCombine/icmp.ll =================================================================== --- llvm/trunk/test/Transforms/InstCombine/icmp.ll +++ llvm/trunk/test/Transforms/InstCombine/icmp.ll @@ -3302,3 +3302,15 @@ ret i1 %cmp } +; Don't crash by assuming the compared values are integers. +define <2 x i1> @PR36583(<2 x i8*>) { +; CHECK-LABEL: @PR36583( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[RES:%.*]] = icmp eq <2 x i8*> %0, zeroinitializer +; CHECK-NEXT: ret <2 x i1> [[RES]] +; +entry: + %cast = ptrtoint <2 x i8*> %0 to <2 x i64> + %res = icmp eq <2 x i64> %cast, zeroinitializer + ret <2 x i1> %res +}