diff options
author | Nikita Popov <npopov@redhat.com> | 2023-11-03 10:46:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-03 10:46:07 +0100 |
commit | e4a4122eb6768b69640173b4c32fd88de4547227 (patch) | |
tree | e0c6343e6a4f10225168345da68dc93877a78e16 /llvm/lib/IR/ConstantFold.cpp | |
parent | e9db60c05e2fb96ff40cbb1f78790abc5de9237e (diff) | |
download | llvm-e4a4122eb6768b69640173b4c32fd88de4547227.zip llvm-e4a4122eb6768b69640173b4c32fd88de4547227.tar.gz llvm-e4a4122eb6768b69640173b4c32fd88de4547227.tar.bz2 |
[IR] Remove zext and sext constant expressions (#71040)
Remove support for zext and sext constant expressions. All places
creating them have been removed beforehand, so this just removes the
APIs and uses of these constant expressions in tests.
There is some additional cleanup that can be done on top of this, e.g.
we can remove the ZExtInst vs ZExtOperator footgun.
This is part of
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179.
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 15a7485..81691a5 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -258,40 +258,6 @@ static Constant *ExtractConstantBytes(Constant *C, unsigned ByteStart, // TODO: Handle the 'partially zero' case. return nullptr; } - - case Instruction::ZExt: { - unsigned SrcBitSize = - cast<IntegerType>(CE->getOperand(0)->getType())->getBitWidth(); - - // If extracting something that is completely zero, return 0. - if (ByteStart*8 >= SrcBitSize) - return Constant::getNullValue(IntegerType::get(CE->getContext(), - ByteSize*8)); - - // If exactly extracting the input, return it. - if (ByteStart == 0 && ByteSize*8 == SrcBitSize) - return CE->getOperand(0); - - // If extracting something completely in the input, if the input is a - // multiple of 8 bits, recurse. - if ((SrcBitSize&7) == 0 && (ByteStart+ByteSize)*8 <= SrcBitSize) - return ExtractConstantBytes(CE->getOperand(0), ByteStart, ByteSize); - - // Otherwise, if extracting a subset of the input, which is not multiple of - // 8 bits, do a shift and trunc to get the bits. - if ((ByteStart+ByteSize)*8 < SrcBitSize) { - assert((SrcBitSize&7) && "Shouldn't get byte sized case here"); - Constant *Res = CE->getOperand(0); - if (ByteStart) - Res = ConstantExpr::getLShr(Res, - ConstantInt::get(Res->getType(), ByteStart*8)); - return ConstantExpr::getTrunc(Res, IntegerType::get(C->getContext(), - ByteSize*8)); - } - - // TODO: Handle the 'partially zero' case. - return nullptr; - } } } @@ -986,16 +952,6 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1, return C1; // X & -1 == X if (ConstantExpr *CE1 = dyn_cast<ConstantExpr>(C1)) { - // (zext i32 to i64) & 4294967295 -> (zext i32 to i64) - if (CE1->getOpcode() == Instruction::ZExt) { - unsigned DstWidth = CI2->getType()->getBitWidth(); - unsigned SrcWidth = - CE1->getOperand(0)->getType()->getPrimitiveSizeInBits(); - APInt PossiblySetBits(APInt::getLowBitsSet(DstWidth, SrcWidth)); - if ((PossiblySetBits & CI2->getValue()) == PossiblySetBits) - return C1; - } - // If and'ing the address of a global with a constant, fold it. if (CE1->getOpcode() == Instruction::PtrToInt && isa<GlobalValue>(CE1->getOperand(0))) { @@ -1056,12 +1012,6 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1, } } break; - case Instruction::AShr: - // ashr (zext C to Ty), C2 -> lshr (zext C, CSA), C2 - if (ConstantExpr *CE1 = dyn_cast<ConstantExpr>(C1)) - if (CE1->getOpcode() == Instruction::ZExt) // Top bits known zero. - return ConstantExpr::getLShr(C1, C2); - break; } } else if (isa<ConstantInt>(C1)) { // If C1 is a ConstantInt and C2 is not, swap the operands. @@ -1461,8 +1411,6 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2, [[fallthrough]]; case Instruction::UIToFP: case Instruction::SIToFP: - case Instruction::ZExt: - case Instruction::SExt: // We can't evaluate floating point casts or truncations. if (CE1Op0->getType()->isFPOrFPVectorTy()) break; @@ -1470,8 +1418,6 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2, // 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()) { - if (CE1->getOpcode() == Instruction::ZExt) isSigned = false; - if (CE1->getOpcode() == Instruction::SExt) isSigned = true; return evaluateICmpRelation(CE1Op0, Constant::getNullValue(CE1Op0->getType()), isSigned); @@ -1828,24 +1774,6 @@ Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, } } - // If the left hand side is an extension, try eliminating it. - if (ConstantExpr *CE1 = dyn_cast<ConstantExpr>(C1)) { - if ((CE1->getOpcode() == Instruction::SExt && - ICmpInst::isSigned(Predicate)) || - (CE1->getOpcode() == Instruction::ZExt && - !ICmpInst::isSigned(Predicate))) { - Constant *CE1Op0 = CE1->getOperand(0); - Constant *CE1Inverse = ConstantExpr::getTrunc(CE1, CE1Op0->getType()); - if (CE1Inverse == CE1Op0) { - // Check whether we can safely truncate the right hand side. - Constant *C2Inverse = ConstantExpr::getTrunc(C2, CE1Op0->getType()); - if (ConstantExpr::getCast(CE1->getOpcode(), C2Inverse, - C2->getType()) == C2) - return ConstantExpr::getICmp(Predicate, CE1Inverse, C2Inverse); - } - } - } - if ((!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) || (C1->isNullValue() && !C2->isNullValue())) { // If C2 is a constant expr and C1 isn't, flip them around and fold the |