diff options
author | Nikita Popov <npopov@redhat.com> | 2025-10-07 17:19:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-10-07 17:19:48 +0200 |
commit | 7e5bb1e58a5c1c96974f7984bd1a2d70bc360d4f (patch) | |
tree | 786e067ff3f209a70e374ab236f963e8e2bf434e /llvm/lib/IR/ConstantFold.cpp | |
parent | e40ff72df1b0e03b17e2abad40c4b97e7ae447d7 (diff) | |
download | llvm-7e5bb1e58a5c1c96974f7984bd1a2d70bc360d4f.zip llvm-7e5bb1e58a5c1c96974f7984bd1a2d70bc360d4f.tar.gz llvm-7e5bb1e58a5c1c96974f7984bd1a2d70bc360d4f.tar.bz2 |
[IR] Require DataLayout for pointer cast elimination (#162279)
isEliminableCastPair() currently tries to support elimination of
ptrtoint/inttoptr cast pairs by assuming that the maximum possible
pointer size is 64 bits. Of course, this is no longer the case nowadays.
This PR changes isEliminableCastPair() to accept an optional DataLayout
argument, which is required to eliminate pointer casts.
This means that we no longer eliminate these cast pairs during ConstExpr
construction, and instead only do it during DL-aware constant folding.
This had a lot of annoying fallout on tests, most of which I've
addressed in advance of this change.
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 9 |
1 files changed, 1 insertions, 8 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 6b202ba..3842b1a 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -55,15 +55,8 @@ foldConstantCastPair( Type *MidTy = Op->getType(); Instruction::CastOps firstOp = Instruction::CastOps(Op->getOpcode()); Instruction::CastOps secondOp = Instruction::CastOps(opc); - - // Assume that pointers are never more than 64 bits wide, and only use this - // for the middle type. Otherwise we could end up folding away illegal - // bitcasts between address spaces with different sizes. - IntegerType *FakeIntPtrTy = Type::getInt64Ty(DstTy->getContext()); - - // Let CastInst::isEliminableCastPair do the heavy lifting. return CastInst::isEliminableCastPair(firstOp, secondOp, SrcTy, MidTy, DstTy, - nullptr, FakeIntPtrTy, nullptr); + /*DL=*/nullptr); } static Constant *FoldBitCast(Constant *V, Type *DestTy) { |