[llvm-branch-commits] [llvm] [SimplifyCFG] Avoid using isNonIntegralPointerType() (PR #159890)

Alexander Richardson via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Sep 19 23:09:05 PDT 2025


================
@@ -525,28 +525,32 @@ static bool dominatesMergePoint(
 static ConstantInt *getConstantInt(Value *V, const DataLayout &DL) {
   // Normal constant int.
   ConstantInt *CI = dyn_cast<ConstantInt>(V);
-  if (CI || !isa<Constant>(V) || !V->getType()->isPointerTy() ||
-      DL.isNonIntegralPointerType(V->getType()))
+  if (CI || !isa<Constant>(V) || !V->getType()->isPointerTy())
     return CI;
 
   // This is some kind of pointer constant. Turn it into a pointer-sized
   // ConstantInt if possible.
-  IntegerType *PtrTy = cast<IntegerType>(DL.getIntPtrType(V->getType()));
+  IntegerType *IntPtrTy = cast<IntegerType>(DL.getIntPtrType(V->getType()));
 
   // Null pointer means 0, see SelectionDAGBuilder::getValue(const Value*).
   if (isa<ConstantPointerNull>(V))
-    return ConstantInt::get(PtrTy, 0);
+    return ConstantInt::get(IntPtrTy, 0);
 
-  // IntToPtr const int.
+  // IntToPtr const int, we can look through this unless the semantics of
+  // inttoptr for this address space aren't a simple bitcast.
+  // TODO: should this be relaxed to hasUnstableRepresentation? The
+  // transformation made here should also be safe for CHERI.
+  if (DL.shouldAvoidIntToPtr(V->getType()))
----------------
arichardson wrote:

Updated to avoid shouldAvoidIntToPtr. Should I drop those helpers from #105735?

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


More information about the llvm-branch-commits mailing list