Skip to content

Commit

Permalink
[ConstantFold] Remove handling for icmp of bitcast
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Nov 3, 2023
1 parent fe20657 commit a7176f8
Showing 1 changed file with 0 additions and 14 deletions.
14 changes: 0 additions & 14 deletions llvm/lib/IR/ConstantFold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GEPOperator>(CE1);
// Ok, since this is a getelementptr, we know that the constant has a
Expand Down

0 comments on commit a7176f8

Please sign in to comment.