Skip to content

[Inline] Remove bitcast handling in CallAnalyzer::stripAndComputeInBoundsConstantOffsets #97988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

dtcxzyw
Copy link
Member

@dtcxzyw dtcxzyw commented Jul 8, 2024

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

Closes #97590.

@llvmbot llvmbot added llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms labels Jul 8, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 8, 2024

@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-llvm-transforms

Author: Yingwei Zheng (dtcxzyw)

Changes

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

Closes #97590.


Full diff: https://github.com/llvm/llvm-project/pull/97988.diff

2 Files Affected:

  • (modified) llvm/lib/Analysis/InlineCost.cpp (-2)
  • (added) llvm/test/Transforms/Inline/pr97590.ll (+28)
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
+}

@goldsteinn
Copy link
Contributor

Does this result in any changes on your benchmark?

@dtcxzyw
Copy link
Member Author

dtcxzyw commented Jul 8, 2024

Does this result in any changes on your benchmark?

No. It should be an NFC patch without #96878.

@goldsteinn
Copy link
Contributor

LGTM a day or two to push so others can have a chance to comment/review.

Copy link
Contributor

@antoniofrighetto antoniofrighetto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM too, thanks!

@dtcxzyw dtcxzyw merged commit be7239e into llvm:main Jul 9, 2024
10 checks passed
@dtcxzyw dtcxzyw deleted the fix-pr97590 branch July 9, 2024 07:08
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
…oundsConstantOffsets` (llvm#97988)

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

Closes llvm#97590.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Inline] Assertion `V->getType()->isPointerTy() && "Unexpected operand type!"' failed.
5 participants