[llvm] be7239e - [Inline] Remove bitcast handling in `CallAnalyzer::stripAndComputeInBoundsConstantOffsets` (#97988)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 9 00:08:08 PDT 2024


Author: Yingwei Zheng
Date: 2024-07-09T15:08:04+08:00
New Revision: be7239e5a60927f5b4932f995dc4b57423ea8534

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

LOG: [Inline] Remove bitcast handling in `CallAnalyzer::stripAndComputeInBoundsConstantOffsets` (#97988)

As we are now using opaque pointers, bitcast handling is no longer
needed.

Closes https://github.com/llvm/llvm-project/issues/97590.

Added: 
    llvm/test/Transforms/Inline/pr97590.ll

Modified: 
    llvm/lib/Analysis/InlineCost.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 94aa8ecf6f558..345e5a0195201 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -2644,8 +2644,6 @@ ConstantInt *CallAnalyzer::stripAndComputeInBoundsConstantOffsets(Value *&V) {
       if (!GEP->isInBounds() || !accumulateGEPOffset(*GEP, Offset))
         return nullptr;
       V = GEP->getPointerOperand();
-    } else if (Operator::getOpcode(V) == Instruction::BitCast) {
-      V = cast<Operator>(V)->getOperand(0);
     } else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
       if (GA->isInterposable())
         break;

diff  --git a/llvm/test/Transforms/Inline/pr97590.ll b/llvm/test/Transforms/Inline/pr97590.ll
new file mode 100644
index 0000000000000..2c2aeb486c49f
--- /dev/null
+++ b/llvm/test/Transforms/Inline/pr97590.ll
@@ -0,0 +1,28 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S -passes=inline < %s | FileCheck %s
+
+; Check that we don't crash when computing the
+; base pointer of `bitcast <1 x ptr> to ptr`
+
+define void @caller(<1 x ptr> %x) {
+; CHECK-LABEL: define void @caller(
+; CHECK-SAME: <1 x ptr> [[X:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[P:%.*]] = bitcast <1 x ptr> [[X]] to ptr
+; CHECK-NEXT:    ret void
+;
+entry:
+  %p = bitcast <1 x ptr> %x to ptr
+  call void @callee(ptr %p)
+  ret void
+}
+
+define void @callee(ptr %p) {
+; CHECK-LABEL: define void @callee(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    ret void
+;
+entry:
+  ret void
+}


        


More information about the llvm-commits mailing list