Bug type: crash
Component: Attributor
Bug location: llvm/lib/Transforms/IPO/AttributorAttributes.cpp: initialize
Issue title: Attributor asserts when compiling rocm device libs
Labels: crash-on-valid
llvm::Attributor
Reported by: arsenm

https://godbolt.org/z/7ddYcExh5

```llvm
; RUN: opt -passes=attributor %s
target datalayout = "e-m:e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128:128:48-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9"
target triple = "amdgcn-amd-amdhsa"

define double @__ocml_acosh_f64() {
entry:
  %0 = tail call double @llvm.fma.f64(double 0.000000e+00, double 0.000000e+00, double 0.000000e+00)
  %cond.i = select i1 false, double 0.000000e+00, double %0
  %add.i46.i = fadd double %cond.i, 0.000000e+00
  %add.i.i33 = fadd double 0.000000e+00, %add.i46.i
  %add.i.i.i39 = fadd double %add.i.i33, 0.000000e+00
  %vecinit1.i.i.i.i43 = insertelement <2 x double> zeroinitializer, double %add.i.i.i39, i64 0
  %call7 = call double @__ocmlpriv_lnep_f64(<2 x double> %vecinit1.i.i.i.i43)
  ret double %call7
}

define double @__ocmlpriv_lnep_f64(<2 x double> %a) {
entry:
  ret double 0.000000e+00
}

declare double @llvm.fma.f64(double, double, double) #0

attributes #0 = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }

```

```
Assertion failed: ((!BB || Parent == NodeTrait::getParent(const_cast<NodeT *>(BB))) && "cannot get DomTreeNode of block with different parent"), function getNode, file GenericDomTree.h, line 425.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: opt -S -p=attributor -o - reduced-attrib.ll
1.	Running pass "attributor" on module "reduced-attrib.ll"
 #0 0x00000001071c4f9c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/bin/opt+0x102774f9c)
 #1 0x00000001071c2f00 llvm::sys::RunSignalHandlers() (/usr/local/bin/opt+0x102772f00)
 #2 0x00000001071c5a44 SignalHandler(int, __siginfo*, void*) (/usr/local/bin/opt+0x102775a44)
 #3 0x000000018f84d6a4 (/usr/lib/system/libsystem_platform.dylib+0x1804ad6a4)
 #4 0x000000018f813848 (/usr/lib/system/libsystem_pthread.dylib+0x180473848)
 #5 0x000000018f71c9e4 (/usr/lib/system/libsystem_c.dylib+0x18037c9e4)
 #6 0x000000018f71bc18 (/usr/lib/system/libsystem_c.dylib+0x18037bc18)
 #7 0x0000000107da615c loadMBUFScalarOperandsFromVGPR(llvm::SIInstrInfo const&, llvm::MachineInstr&, llvm::ArrayRef<llvm::MachineOperand*>, llvm::MachineDominatorTree*, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>) (.cold.20) (/usr/local/bin/opt+0x10335615c)
 #8 0x000000010695be6c llvm::DominatorTreeBase<llvm::BasicBlock, false>::getNodeIndex(llvm::BasicBlock const*) const (/usr/local/bin/opt+0x101f0be6c)
 #9 0x0000000106374ccc isGuaranteedNotToBeUndefOrPoison(llvm::Value const*, llvm::AssumptionCache*, llvm::Instruction const*, llvm::DominatorTree const*, unsigned int, UndefPoisonKind) (/usr/local/bin/opt+0x101924ccc)
```


Fix patch:
commit 485eb62afd7edb1ecb13c975bf62da03ff166b60
Author: Matt Arsenault <Matthew.Arsenault@amd.com>
Date:   Fri Jan 30 22:38:07 2026 +0100

    Attributor: Use anchor scope for SimplifyQuery context (#178958)
    
    This was asserting in computeKnownFPClass when a dominator tree
    check happened across functions.
    
    Fixes #178954

diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 9796b4f4cc40..86bdb7c49c0e 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -10495,7 +10495,7 @@ struct AANoFPClassImpl : AANoFPClass {
       const DominatorTree *DT = nullptr;
       AssumptionCache *AC = nullptr;
       const TargetLibraryInfo *TLI = nullptr;
-      Function *F = getAssociatedFunction();
+      Function *F = getAnchorScope();
       if (F) {
         TLI = InfoCache.getTargetLibraryInfoForFunction(*F);
         if (!F->isDeclaration()) {


Regression tests:
file: llvm/test/Transforms/Attributor/nofpclass.ll
commands: opt -passes=attributor -S < %s
tests: test_name: <module>
test_body: ; RUN: opt -passes=attributor %s
target datalayout = "e-m:e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128:128:48-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9"
target triple = "amdgcn-amd-amdhsa"

define double @__ocml_acosh_f64() {
entry:
  %0 = tail call double @llvm.fma.f64(double 0.000000e+00, double 0.000000e+00, double 0.000000e+00)
  %cond.i = select i1 false, double 0.000000e+00, double %0
  %add.i46.i = fadd double %cond.i, 0.000000e+00
  %add.i.i33 = fadd double 0.000000e+00, %add.i46.i
  %add.i.i.i39 = fadd double %add.i.i33, 0.000000e+00
  %vecinit1.i.i.i.i43 = insertelement <2 x double> zeroinitializer, double %add.i.i.i39, i64 0
  %call7 = call double @__ocmlpriv_lnep_f64(<2 x double> %vecinit1.i.i.i.i43)
  ret double %call7
}

define double @__ocmlpriv_lnep_f64(<2 x double> %a) {
entry:
  ret double 0.000000e+00
}

declare double @llvm.fma.f64(double, double, double) #0

attributes #0 = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }