From 3ff4004b3d11265b783bdf2746eed60768736c0a Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 3 Nov 2023 12:22:59 +0100 Subject: [PATCH] [ConstantFold] Remove handling for icmp of bitcast This only handles the case where the bitcast result is an integer or pointer, and the input is not FP. This means that the input can only be a vector. However, converting a comparison of the whole vector into an element-wise comparison is generally not correct. I assume that this code was originally intended to handle the case where a pointer bitcast is compared to a null pointer, which is no longer relevant with opaque pointers. Given the complete lack of test coverage, and the risk of miscompiles if this code actually did something, I'm opting to remove it entirely. --- llvm/lib/IR/ConstantFold.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index a10796e6da99..a4df57940653 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -1243,20 +1243,6 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2, Constant *CE1Op0 = CE1->getOperand(0); switch (CE1->getOpcode()) { - case Instruction::BitCast: - // We can't evaluate floating point casts or truncations. - if (CE1Op0->getType()->isFPOrFPVectorTy()) - break; - - // If the cast is not actually changing bits, and the second operand is a - // null pointer, do the comparison with the pre-casted value. - if (V2->isNullValue() && CE1->getType()->isIntOrPtrTy()) { - return evaluateICmpRelation(CE1Op0, - Constant::getNullValue(CE1Op0->getType()), - isSigned); - } - break; - case Instruction::GetElementPtr: { GEPOperator *CE1GEP = cast(CE1); // Ok, since this is a getelementptr, we know that the constant has a