[llvm] [IR] Handle trunc for ptrtoaddr(inttoptr) cast pair (PR #162842)
Alexander Richardson via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 10 09:15:18 PDT 2025
================
@@ -637,6 +637,30 @@ TEST(InstructionsTest, isEliminableCastPair) {
Int64Ty, &DL1),
0U);
+ // Destination larger than source. Pointer type same as destination.
+ EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr,
+ CastInst::PtrToInt, Int16Ty, PtrTy64,
+ Int64Ty, &DL1),
+ CastInst::ZExt);
+
+ // Destination larger than source. Pointer type different from destination.
+ EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr,
+ CastInst::PtrToInt, Int16Ty, PtrTy32,
+ Int64Ty, &DL1),
+ CastInst::ZExt);
+
+ // Destination smaller than source. Pointer type same as source.
+ EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr,
+ CastInst::PtrToInt, Int64Ty, PtrTy64,
+ Int16Ty, &DL1),
+ CastInst::Trunc);
+
+ // Destination smaller than source. Pointer type different from source.
+ EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr,
----------------
arichardson wrote:
Could you also add a ptrtoaddr test here with e.g. `p2:64:64:64:32` data layout? Showing it only works for the address bits?
https://github.com/llvm/llvm-project/pull/162842
More information about the llvm-commits
mailing list