[llvm] [ConstantFolding] Support ptrtoaddr in ConstantFoldCompareInstOperands (PR #162653)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 9 10:09:16 PDT 2025


================
@@ -1225,7 +1225,8 @@ Constant *llvm::ConstantFoldCompareInstOperands(
 
       // Only do this transformation if the int is intptrty in size, otherwise
       // there is a truncation or extension that we aren't modeling.
-      if (CE0->getOpcode() == Instruction::PtrToInt) {
+      if (CE0->getOpcode() == Instruction::PtrToInt ||
+          CE0->getOpcode() == Instruction::PtrToAddr) {
         Type *IntPtrTy = DL.getIntPtrType(CE0->getOperand(0)->getType());
----------------
nikic wrote:

This PR is under the assumption that icmp compares all bits. I felt that there wasn't sufficient consensus for the address-only interpretation yet. I'll put this into draft for now and revisit this once we have more clarity.

https://github.com/llvm/llvm-project/pull/162653


More information about the llvm-commits mailing list