[PATCH] D139911: [InstCombine][WIP] Explicitly disable simplifyIntToPtrRoundTripCast for vectors.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 21:29:57 PST 2022


craig.topper created this revision.
craig.topper added reviewers: efriedma, spatel, sdesmalen.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added a subscriber: alextsao1999.
Herald added a project: LLVM.

This code compares getPointerTypeSizeInBits and getTypeSizeInBits.
getPointerTypeSizeInBits contains a call to getScalarType while
getTypeSizeInBits does not. This makes the code incorrect for vectors.

Additionally, for scalable vectors getTypeSizeInBits returns a scalable
TypeSize but getPointerTypeSizeInBits always returns an unsigned
integer. I believe the comparison forces the scalable TypeSize to
be converted to unsigned which triggers a warning.

Fixes PR59480.

Still need to add a test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139911

Files:
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp


Index: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -370,10 +370,12 @@
 // inttoptr ( ptrtoint (x) ) --> x
 Value *InstCombinerImpl::simplifyIntToPtrRoundTripCast(Value *Val) {
   auto *IntToPtr = dyn_cast<IntToPtrInst>(Val);
-  if (IntToPtr && DL.getPointerTypeSizeInBits(IntToPtr->getDestTy()) ==
-                      DL.getTypeSizeInBits(IntToPtr->getSrcTy())) {
+  if (!IntToPtr)
+    return nullptr;
+  Type *CastTy = IntToPtr->getDestTy();
+  if (!CastTy->isVectorTy() && DL.getPointerTypeSizeInBits(CastTy) ==
+                                   DL.getTypeSizeInBits(IntToPtr->getSrcTy())) {
     auto *PtrToInt = dyn_cast<PtrToIntInst>(IntToPtr->getOperand(0));
-    Type *CastTy = IntToPtr->getDestTy();
     if (PtrToInt &&
         CastTy->getPointerAddressSpace() ==
             PtrToInt->getSrcTy()->getPointerAddressSpace() &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139911.482356.patch
Type: text/x-patch
Size: 1049 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221213/88116255/attachment.bin>


More information about the llvm-commits mailing list