Bug type: crash
Component: InlineCost
Bug location: llvm/lib/Analysis/InlineCost.cpp: CallAnalyzer::stripAndComputeInBoundsConstantOffsets
Issue title: [Inline] Assertion `V->getType()->isPointerTy() && "Unexpected operand type!"' failed.
Labels: crash-on-valid
llvm:analysis
Reported by: dtcxzyw

Reproducer: https://godbolt.org/z/qGc1Kx5YK
```
; bin/opt -passes=inline reduced.ll -S
define i32 @func_120(i1 %tobool626, ptr %g_231, ptr %l_506, i1 %tobool724, ptr %p) {
entry:
  %0 = bitcast i1 %tobool626 to <1 x i1>
  call void @llvm.masked.store.v1i64.p0(<1 x i64> zeroinitializer, ptr %g_231, i32 8, <1 x i1> %0)
  %1 = xor i1 %tobool626, true
  %2 = bitcast i1 %1 to <1 x i1>
  %3 = call <1 x ptr> @llvm.masked.load.v1p0.p0(ptr %g_231, i32 8, <1 x i1> %2, <1 x ptr> poison)
  %4 = bitcast <1 x ptr> %3 to ptr
  br i1 %tobool626, label %common.ret, label %if.else647

common.ret:                                       ; preds = %entry, %lor.end739
  ret i32 0

if.else647:                                       ; preds = %entry
  br i1 %tobool724, label %land.rhs725, label %lor.end739

land.rhs725:                                      ; preds = %if.else647
  %call726 = load i32, ptr %p, align 4
  br label %lor.end739

lor.end739:                                       ; preds = %land.rhs725, %if.else647
  %call745 = call i32 @func_136(ptr %4)
  br label %common.ret
}

define i32 @func_136(ptr nocapture readnone %p_137) {
entry:
  ret i32 0
}

```
```
opt: /root/llvm-project/llvm/lib/Analysis/InlineCost.cpp:2656: llvm::ConstantInt* {anonymous}::CallAnalyzer::stripAndComputeInBoundsConstantOffsets(llvm::Value*&): Assertion `V->getType()->isPointerTy() && "Unexpected operand type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=inline <source>
1.	Running pass "cgscc(inline)" on module "<source>"
 #0 0x0000000004e7cf38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7cf38)
 #1 0x0000000004e7a69c SignalHandler(int) Signals.cpp:0:0
 #2 0x000077b96f042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x000077b96f0969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x000077b96f042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x000077b96f0287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x000077b96f02871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x000077b96f039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x00000000043ea53a (anonymous namespace)::CallAnalyzer::analyze() (.part.0) InlineCost.cpp:0:0
 #9 0x00000000043eb650 llvm::getInlineCost(llvm::CallBase&, llvm::Function*, llvm::InlineParams const&, llvm::TargetTransformInfo&, llvm::function_ref<llvm::AssumptionCache& (llvm::Function&)>, llvm::function_ref<llvm::TargetLibraryInfo const& (llvm::Function&)>, llvm::function_ref<llvm::BlockFrequencyInfo& (llvm::Function&)>, llvm::ProfileSummaryInfo*, llvm::OptimizationRemarkEmitter*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43eb650)
#10 0x00000000043ebba6 llvm::getInlineCost(llvm::CallBase&, llvm::InlineParams const&, llvm::TargetTransformInfo&, llvm::function_ref<llvm::AssumptionCache& (llvm::Function&)>, llvm::function_ref<llvm::TargetLibraryInfo const& (llvm::Function&)>, llvm::function_ref<llvm::BlockFrequencyInfo& (llvm::Function&)>, llvm::ProfileSummaryInfo*, llvm::OptimizationRemarkEmitter*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43ebba6)
#11 0x00000000043ed0ab llvm::InlineCost llvm::function_ref<llvm::InlineCost (llvm::CallBase&)>::callback_fn<getDefaultInlineAdvice(llvm::CallBase&, llvm::AnalysisManager<llvm::Function>&, llvm::InlineParams const&)::'lambda2'(llvm::CallBase&)>(long, llvm::CallBase&) InlineAdvisor.cpp:0:0
#12 0x00000000043f310d llvm::shouldInline(llvm::CallBase&, llvm::function_ref<llvm::InlineCost (llvm::CallBase&)>, llvm::OptimizationRemarkEmitter&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43f310d)
#13 0x00000000043f4af5 getDefaultInlineAdvice(llvm::CallBase&, llvm::AnalysisManager<llvm::Function>&, llvm::InlineParams const&) InlineAdvisor.cpp:0:0
#14 0x00000000043f4d3b llvm::DefaultInlineAdvisor::getAdviceImpl(llvm::CallBase&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43f4d3b)
#15 0x00000000043eda71 llvm::InlineAdvisor::getAdvice(llvm::CallBase&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43eda71)
#16 0x000000000371e48d llvm::InlinerPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x371e48d)
#17 0x0000000002e127ae llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::InlinerPass, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e127ae)
#18 0x000000000431385b llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x431385b)
#19 0x0000000002e1154e llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e1154e)
#20 0x00000000043155b9 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43155b9)
#21 0x0000000002e1152e llvm::detail::PassModel<llvm::Module, llvm::ModuleToPostOrderCGSCCPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e1152e)
#22 0x0000000004c780c0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c780c0)
#23 0x00000000008d8702 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d8702)
#24 0x00000000008cb60c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8cb60c)
#25 0x000077b96f029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#26 0x000077b96f029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#27 0x00000000008c2a6e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8c2a6e)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
https://github.com/llvm/llvm-project/blob/f1a8f94bba8b090a0d667065e4b8b4fc66b6a5cc/llvm/lib/Analysis/InlineCost.cpp#L2647-L2648
should be removed as we use opaque pointers now.


Comments: author: dtcxzyw
body: Related patch: #96878 
author: dtcxzyw
body: Reduced reproducer: https://godbolt.org/z/rbjK6ETEW
```
; bin/opt -passes=inline reduced.ll -S
define void @caller(<1 x ptr> %x) {
entry:
  %p = bitcast <1 x ptr> %x to ptr
  call void @callee(ptr %p)
  ret void
}

define void @callee(ptr %p) {
entry:
  ret void
}
```

Fix patch:
commit be7239e5a60927f5b4932f995dc4b57423ea8534
Author: Yingwei Zheng <dtcxzyw2333@gmail.com>
Date:   Tue Jul 9 15:08:04 2024 +0800

    [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.

diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 94aa8ecf6f55..345e5a019520 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;


Regression tests:
file: llvm/test/Transforms/Inline/pr97590.ll
commands: opt -S -passes=inline < %s
tests: test_name: <module>
test_body: 
; 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) {
;
entry:
  %p = bitcast <1 x ptr> %x to ptr
  call void @callee(ptr %p)
  ret void
}

define void @callee(ptr %p) {
;
entry:
  ret void
}