[llvm] ae983de - [InferAddressSpaces] NFC: For noop IntToPtr/PtrToInt pair cast to operator instead of PtrToInt

Reshabh Sharma via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 28 06:54:51 PDT 2021


Author: Reshabh Sharma
Date: 2021-06-28T19:24:26+05:30
New Revision: ae983de6cce23dfeeb629395f86528e911218ba4

URL: https://github.com/llvm/llvm-project/commit/ae983de6cce23dfeeb629395f86528e911218ba4
DIFF: https://github.com/llvm/llvm-project/commit/ae983de6cce23dfeeb629395f86528e911218ba4.diff

LOG: [InferAddressSpaces] NFC: For noop IntToPtr/PtrToInt pair cast to operator instead of PtrToInt

Compiler crashes at an assertion while casting operands to PtrToIntInst at some cases when
ptrtoint is present as an explicit operand to inttoptr. Explicit instruction operator as
operand can not be casted to an Instruction.

This patch replaces cast from PtrToInst to Operator which are later checked for constant
expressions.

Differential Revision: https://reviews.llvm.org/D105002

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
    llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
index 332eb10ac16b..aa26bf11c299 100644
--- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -471,7 +471,7 @@ InferAddressSpacesImpl::collectFlatAddressExpressions(Function &F) const {
     } else if (auto *I2P = dyn_cast<IntToPtrInst>(&I)) {
       if (isNoopPtrIntCastPair(cast<Operator>(I2P), *DL, TTI))
         PushPtrOperand(
-            cast<PtrToIntInst>(I2P->getOperand(0))->getPointerOperand());
+            cast<Operator>(I2P->getOperand(0))->getOperand(0));
     }
   }
 

diff  --git a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll
index 24cab4f7bf6e..d45b0ab8803f 100644
--- a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll
+++ b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll
@@ -69,6 +69,16 @@ define i32* @noop_ptrint_pair_ce2() {
   ret i32* inttoptr (i64 ptrtoint (i32 addrspace(1)* @g to i64) to i32*)
 }
 
+; COMMON-LABEL: @noop_ptrint_pair_ce3(
+; AMDGCN-NEXT: %i = inttoptr i64 ptrtoint (i32 addrspace(1)* @g to i64) to i32*
+; AMDGCN-NEXT: ret void
+; NOTTI-NEXT: %i = inttoptr i64 ptrtoint (i32 addrspace(1)* @g to i64) to i32*
+; NOTTI-NEXT: ret void
+define void @noop_ptrint_pair_ce3() {
+  %i = inttoptr i64 ptrtoint (i32 addrspace(1)* @g to i64) to i32*
+  ret void
+}
+
 ; COMMON-LABEL: @non_noop_ptrint_pair_ce(
 ; AMDGCN-NEXT: store i32 0, i32* inttoptr (i64 ptrtoint (i32 addrspace(3)* @l to i64) to i32*)
 ; AMDGCN-NEXT: ret void


        


More information about the llvm-commits mailing list