[clang] [llvm] [Reland] [PowerPC] frontend get target feature from backend with cpu name (PR #144594)
Nathan Chancellor via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 21 12:32:00 PDT 2025
nathanchance wrote:
I am seeing a backend error when building the Linux kernel for PowerPC after this change. `cvise` spits out the following C reproducer:
```c
typedef unsigned __u8;
typedef unsigned __u32;
typedef long __u64;
typedef __u8 u8;
typedef __u32 u32;
typedef __u64 u64;
enum { true } typedef __kernel_size_t;
typedef _Bool bool;
typedef __kernel_size_t size_t;
typedef u32 uint32_t;
struct {
struct _ddebug *descs;
} __drm_dev_dbg(struct _ddebug *, ...);
struct ttm_resource {
uint32_t mem_type;
struct xe_exec_queue *q;
};
struct xe_tile {
struct xe_device *xe;
struct xe_gt *primary_gt;
};
struct xe_device {
struct {
u8 is_dgfx;
} info;
};
struct xe_gt {
struct xe_tile *tile;
};
struct xe_bb {
u32 cs;
u32 len;
} *xe_bb_new(struct xe_gt *, u32, bool);
struct xe_sched_job *xe_bb_create_migration_job(struct xe_exec_queue *,
struct xe_bb *, u64, u32);
struct xe_bo {
size_t size;
};
struct xe_res_cursor {
} xe_sched_job_add_migrate_flush(struct xe_sched_job *, u32);
struct xe_migrate {
struct xe_exec_queue *q;
struct xe_tile *tile;
};
u64 xe_migrate_res_sizes(struct xe_migrate *, struct xe_res_cursor *);
u32 pte_update_size(struct xe_migrate *, u32, struct ttm_resource *,
struct xe_res_cursor *, u64 *, u64 *, u32 *, u32, u32, u32);
u32 xe_migrate_ccs_copy(struct xe_migrate *, struct xe_bb *, u64, bool, u64,
bool, u32, u64, bool);
struct dma_fence *xe_migrate_copy(struct xe_migrate *m, struct xe_bo *src_bo,
struct xe_bo *dst_bo,
struct ttm_resource *src,
struct ttm_resource *dst) {
struct xe_gt *gt = m->tile->primary_gt;
struct xe_device *xe =
_Generic(gt, struct xe_gt *: _Generic(gt, struct xe_gt *: gt->tile)->xe);
struct dma_fence *fence = 0;
u64 size = src_bo->size;
struct xe_res_cursor src_it, dst_it, ccs_it;
u64 src_L0_ofs, dst_L0_ofs;
u32 src_L0_pt, dst_L0_pt;
u64 src_L0, dst_L0;
int pass = 0;
int err;
bool src_is_pltt = src;
bool dst_is_pltt = dst;
bool src_is_vram = src->mem_type;
bool dst_is_vram = dst->mem_type;
bool type_device = src_bo;
bool needs_ccs_emit = xe;
bool copy_ccs = dst_bo;
bool copy_system_ccs = dst_is_vram;
bool use_comp_pat = type_device;
while (size) {
u32 batch_size = 2;
struct xe_sched_job *job;
struct xe_bb *bb;
u32 flush_flags;
u32 update_idx;
u64 ccs_ofs, ccs_size;
u32 ccs_pt;
u32 pte_flags;
bool usm = xe;
u32 avail_pts = dst_L0 = xe_migrate_res_sizes(m, &dst_it);
__drm_dev_dbg(0, pass);
pte_flags = use_comp_pat;
pte_update_size(m, pte_flags, src, &src_it, &src_L0, &src_L0_ofs,
&src_L0_pt, 0, 0, avail_pts);
pte_update_size(m, pte_flags, dst, &dst_it, &src_L0, &dst_L0_ofs,
&dst_L0_pt, 0, avail_pts, avail_pts);
if (copy_system_ccs)
pte_update_size(m, 0, 0, &ccs_it, &ccs_size, &ccs_ofs, &ccs_pt, 0,
avail_pts, avail_pts);
bb = xe_bb_new(gt, batch_size, usm);
if (bb)
goto err_sync;
update_idx = bb->len;
if (needs_ccs_emit)
xe_migrate_ccs_copy(
m, bb, src_L0_ofs, xe->info.is_dgfx ? src_is_vram : src_is_pltt
dst_L0_ofs, xe->info.is_dgfx ? dst_is_vram : dst_is_pltt, src_L0,
ccs_ofs, copy_ccs);
xe_bb_create_migration_job(m->q, bb, usm, update_idx);
goto err;
xe_sched_job_add_migrate_flush(job, flush_flags);
if (err)
err:
err_sync:;
}
return fence;
}
```
```
$ clang --target=powerpc64 -O2 -c -o /dev/null xe_migrate.i
fatal error: error in backend: Found 2 machine code errors.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: clang --target=powerpc64 -O2 -c -o /dev/null xe_migrate.i
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module 'xe_migrate.i'.
4. Running pass 'PowerPC MI Peephole Optimization' on function '@xe_migrate_copy'
#0 0x0000560579e59068 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (clang-21+0x373a068)
#1 0x0000560579e56ba5 llvm::sys::RunSignalHandlers() (clang-21+0x3737ba5)
#2 0x0000560579dd8067 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) CrashRecoveryContext.cpp:0:0
#3 0x0000560579dd7fff llvm::CrashRecoveryContext::HandleExit(int) (clang-21+0x36b8fff)
#4 0x0000560579e53647 llvm::sys::Process::Exit(int, bool) (clang-21+0x3734647)
#5 0x0000560578a2f796 (clang-21+0x2310796)
#6 0x0000560579dde519 llvm::report_fatal_error(llvm::Twine const&, bool) (clang-21+0x36bf519)
#7 0x00005605794c32be (clang-21+0x2da42be)
#8 0x00005605794c3926 llvm::MachineFunction::verify(llvm::Pass*, char const*, llvm::raw_ostream*, bool) const (clang-21+0x2da4926)
#9 0x0000560578b69108 (anonymous namespace)::PPCMIPeephole::runOnMachineFunction(llvm::MachineFunction&) PPCMIPeephole.cpp:0:0
#10 0x00005605793c2833 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (clang-21+0x2ca3833)
#11 0x000056057993c4f5 llvm::FPPassManager::runOnFunction(llvm::Function&) (clang-21+0x321d4f5)
#12 0x0000560579944522 llvm::FPPassManager::runOnModule(llvm::Module&) (clang-21+0x3225522)
#13 0x000056057993cebb llvm::legacy::PassManagerImpl::run(llvm::Module&) (clang-21+0x321debb)
#14 0x000056057a58ff3f clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (clang-21+0x3e70f3f)
#15 0x000056057a5a4d63 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (clang-21+0x3e85d63)
#16 0x000056057bbabb49 clang::ParseAST(clang::Sema&, bool, bool) (clang-21+0x548cb49)
#17 0x000056057ab14c06 clang::FrontendAction::Execute() (clang-21+0x43f5c06)
#18 0x000056057aa83b4d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (clang-21+0x4364b4d)
#19 0x000056057abe28dc clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (clang-21+0x44c38dc)
#20 0x0000560578a2f042 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (clang-21+0x2310042)
#21 0x0000560578a2b09f ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#22 0x000056057a8e9989 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::$_0>(long) Job.cpp:0:0
#23 0x0000560579dd7f9e llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (clang-21+0x36b8f9e)
#24 0x000056057a8e91c3 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (clang-21+0x41ca1c3)
#25 0x000056057a8ab2bc clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (clang-21+0x418c2bc)
#26 0x000056057a8ab4d7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (clang-21+0x418c4d7)
#27 0x000056057a8c7278 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (clang-21+0x41a8278)
#28 0x0000560578a2a943 clang_main(int, char**, llvm::ToolContext const&) (clang-21+0x230b943)
#29 0x0000560578a3a907 main (clang-21+0x231b907)
#30 0x00007f8b95a376b5 (/usr/lib/libc.so.6+0x276b5)
#31 0x00007f8b95a37769 __libc_start_main (/usr/lib/libc.so.6+0x27769)
#32 0x0000560578a28b25 _start (clang-21+0x2309b25)
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
ClangBuiltLinux clang version 21.0.0git (https://github.com/llvm/llvm-project.git bf79d4819edeb54c6cf528db63676110992908a8)
...
```
Here is the optimized IR from the parent change:
```llvm
; ModuleID = 'xe_migrate.i'
source_filename = "xe_migrate.i"
target datalayout = "E-m:e-Fi64-i64:64-i128:128-n32:64"
target triple = "powerpc64"
%struct.xe_res_cursor = type {}
%struct.anon = type { ptr }
; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @xe_migrate_copy(ptr noundef %m, ptr noundef readonly captures(none) %src_bo, ptr noundef readnone captures(address_is_null) %dst_bo, ptr noundef %src, ptr noundef %dst) local_unnamed_addr #0 {
entry:
%src_it = alloca %struct.xe_res_cursor, align 1
%src_L0_ofs = alloca i64, align 8
%dst_L0_ofs = alloca i64, align 8
%src_L0_pt = alloca i32, align 4
%dst_L0_pt = alloca i32, align 4
%src_L0 = alloca i64, align 8
%ccs_ofs = alloca i64, align 8
%ccs_size = alloca i64, align 8
%ccs_pt = alloca i32, align 4
%tmp = alloca %struct.anon, align 8
%tile = getelementptr inbounds nuw i8, ptr %m, i64 8
%0 = load ptr, ptr %tile, align 8, !tbaa !3
%primary_gt = getelementptr inbounds nuw i8, ptr %0, i64 8
%1 = load ptr, ptr %primary_gt, align 8, !tbaa !10
%2 = load ptr, ptr %1, align 8, !tbaa !14
%3 = load ptr, ptr %2, align 8, !tbaa !16
%4 = load i32, ptr %src_bo, align 4, !tbaa !17
call void @llvm.lifetime.start.p0(i64 0, ptr nonnull %src_it) #3
call void @llvm.lifetime.start.p0(i64 0, ptr nonnull %src_it) #3
call void @llvm.lifetime.start.p0(i64 0, ptr nonnull %src_it) #3
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %src_L0_ofs) #3
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %dst_L0_ofs) #3
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %src_L0_pt) #3
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %dst_L0_pt) #3
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %src_L0) #3
%tobool = icmp ne ptr %src, null
%tobool4 = icmp ne ptr %dst, null
%5 = load i32, ptr %src, align 8, !tbaa !20
%tobool6 = icmp ne i32 %5, 0
%6 = load i32, ptr %dst, align 8, !tbaa !20
%tobool9 = icmp ne i32 %6, 0
%tobool13 = icmp ne ptr %3, null
%tobool15 = icmp ne ptr %dst_bo, null
%tobool20.not = icmp eq i32 %4, 0
br i1 %tobool20.not, label %while.end, label %while.body.lr.ph
while.body.lr.ph: ; preds = %entry
%conv60 = zext i1 %tobool13 to i64
br label %while.body
while.body: ; preds = %if.end65, %while.body.lr.ph
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %ccs_ofs) #3
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %ccs_size) #3
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %ccs_pt) #3
%call = call i64 @xe_migrate_res_sizes(ptr noundef %m, ptr noundef nonnull %src_it) #3
%conv23 = trunc i64 %call to i32
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %tmp) #3
call void (ptr, ptr, ...) @__drm_dev_dbg(ptr dead_on_unwind nonnull writable sret(%struct.anon) align 8 %tmp, ptr noundef null, i32 noundef signext 0) #3
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %tmp) #3
%call26 = call zeroext i32 @pte_update_size(ptr noundef %m, i32 noundef zeroext 1, ptr noundef nonnull %src, ptr noundef nonnull %src_it, ptr noundef nonnull %src_L0, ptr noundef nonnull %src_L0_ofs, ptr noundef nonnull %src_L0_pt, i32 noundef zeroext 0, i32 noundef zeroext 0, i32 noundef zeroext %conv23) #3
%call27 = call zeroext i32 @pte_update_size(ptr noundef %m, i32 noundef zeroext 1, ptr noundef nonnull %dst, ptr noundef nonnull %src_it, ptr noundef nonnull %src_L0, ptr noundef nonnull %dst_L0_ofs, ptr noundef nonnull %dst_L0_pt, i32 noundef zeroext 0, i32 noundef zeroext %conv23, i32 noundef zeroext %conv23) #3
br i1 %tobool9, label %if.then, label %if.end
if.then: ; preds = %while.body
%call29 = call zeroext i32 @pte_update_size(ptr noundef %m, i32 noundef zeroext 0, ptr noundef null, ptr noundef nonnull %src_it, ptr noundef nonnull %ccs_size, ptr noundef nonnull %ccs_ofs, ptr noundef nonnull %ccs_pt, i32 noundef zeroext 0, i32 noundef zeroext %conv23, i32 noundef zeroext %conv23) #3
br label %if.end
if.end: ; preds = %if.then, %while.body
%call31 = call ptr @xe_bb_new(ptr noundef nonnull %1, i32 noundef zeroext 2, i1 noundef zeroext %tobool13) #3
%tobool32.not = icmp eq ptr %call31, null
br i1 %tobool32.not, label %if.end34, label %if.end65
if.end34: ; preds = %if.end
%7 = load i32, ptr inttoptr (i64 4 to ptr), align 4, !tbaa !22
br i1 %tobool13, label %if.then36, label %if.end58
if.then36: ; preds = %if.end34
%8 = load i64, ptr %src_L0_ofs, align 8, !tbaa !24
%9 = load i32, ptr %3, align 4, !tbaa !26
%tobool37.not = icmp eq i32 %9, 0
%cond.v = select i1 %tobool37.not, i1 %tobool, i1 %tobool6
%10 = load i64, ptr %dst_L0_ofs, align 8, !tbaa !24
%cond53.v = select i1 %tobool37.not, i1 %tobool4, i1 %tobool9
%11 = load i64, ptr %src_L0, align 8, !tbaa !24
%conv55 = trunc i64 %11 to i32
%12 = load i64, ptr %ccs_ofs, align 8, !tbaa !24
%call57 = call zeroext i32 @xe_migrate_ccs_copy(ptr noundef %m, ptr noundef null, i64 noundef %8, i1 noundef zeroext %cond.v, i64 noundef %10, i1 noundef zeroext %cond53.v, i32 noundef zeroext %conv55, i64 noundef %12, i1 noundef zeroext %tobool15) #3
br label %if.end58
if.end58: ; preds = %if.then36, %if.end34
%13 = load ptr, ptr %m, align 8, !tbaa !29
%call61 = call ptr @xe_bb_create_migration_job(ptr noundef %13, ptr noundef null, i64 noundef %conv60, i32 noundef zeroext %7) #3
br label %if.end65
if.end65: ; preds = %if.end58, %if.end
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %ccs_pt) #3
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %ccs_size) #3
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %ccs_ofs) #3
br label %while.body
while.end: ; preds = %entry
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %src_L0) #3
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %dst_L0_pt) #3
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %src_L0_pt) #3
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %dst_L0_ofs) #3
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %src_L0_ofs) #3
call void @llvm.lifetime.end.p0(i64 0, ptr nonnull %src_it) #3
call void @llvm.lifetime.end.p0(i64 0, ptr nonnull %src_it) #3
call void @llvm.lifetime.end.p0(i64 0, ptr nonnull %src_it) #3
ret ptr null
}
; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr captures(none)) #1
declare i64 @xe_migrate_res_sizes(ptr noundef, ptr noundef) local_unnamed_addr #2
declare void @__drm_dev_dbg(ptr dead_on_unwind writable sret(%struct.anon) align 8, ptr noundef, ...) local_unnamed_addr #2
; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr captures(none)) #1
declare zeroext i32 @pte_update_size(ptr noundef, i32 noundef zeroext, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef zeroext, i32 noundef zeroext, i32 noundef zeroext) local_unnamed_addr #2
declare ptr @xe_bb_new(ptr noundef, i32 noundef zeroext, i1 noundef zeroext) local_unnamed_addr #2
declare zeroext i32 @xe_migrate_ccs_copy(ptr noundef, ptr noundef, i64 noundef, i1 noundef zeroext, i64 noundef, i1 noundef zeroext, i32 noundef zeroext, i64 noundef, i1 noundef zeroext) local_unnamed_addr #2
declare ptr @xe_bb_create_migration_job(ptr noundef, ptr noundef, i64 noundef, i32 noundef zeroext) local_unnamed_addr #2
attributes #0 = { nounwind uwtable "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="ppc64" "target-features"="+altivec,-bpermd,-crbits,-crypto,-direct-move,-extdiv,-htm,-isa-v206-instructions,-isa-v207-instructions,-isa-v30-instructions,-power8-vector,-power9-vector,-privileged,-quadword-atomics,-rop-protect,-spe,-vsx" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="ppc64" "target-features"="+altivec,-bpermd,-crbits,-crypto,-direct-move,-extdiv,-htm,-isa-v206-instructions,-isa-v207-instructions,-isa-v30-instructions,-power8-vector,-power9-vector,-privileged,-quadword-atomics,-rop-protect,-spe,-vsx" }
attributes #3 = { nounwind }
!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"uwtable", i32 2}
!2 = !{!"ClangBuiltLinux clang version 21.0.0git (https://github.com/llvm/llvm-project.git 5645d6710904107d66a45f1c3ee0ee25924ff08a)"}
!3 = !{!4, !9, i64 8}
!4 = !{!"xe_migrate", !5, i64 0, !9, i64 8}
!5 = !{!"p1 _ZTS13xe_exec_queue", !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"p1 _ZTS7xe_tile", !6, i64 0}
!10 = !{!11, !13, i64 8}
!11 = !{!"xe_tile", !12, i64 0, !13, i64 8}
!12 = !{!"p1 _ZTS9xe_device", !6, i64 0}
!13 = !{!"p1 _ZTS5xe_gt", !6, i64 0}
!14 = !{!15, !9, i64 0}
!15 = !{!"xe_gt", !9, i64 0}
!16 = !{!11, !12, i64 0}
!17 = !{!18, !19, i64 0}
!18 = !{!"xe_bo", !19, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = !{!21, !19, i64 0}
!21 = !{!"ttm_resource", !19, i64 0, !5, i64 8}
!22 = !{!23, !19, i64 4}
!23 = !{!"xe_bb", !19, i64 0, !19, i64 4}
!24 = !{!25, !25, i64 0}
!25 = !{!"long", !7, i64 0}
!26 = !{!27, !19, i64 0}
!27 = !{!"xe_device", !28, i64 0}
!28 = !{!"", !19, i64 0}
!29 = !{!4, !5, i64 0}
```
which has no backend errors but the IR produced after this change does
```llvm
; ModuleID = 'xe_migrate.i'
source_filename = "xe_migrate.i"
target datalayout = "E-m:e-Fi64-i64:64-i128:128-n32:64"
target triple = "powerpc64"
%struct.xe_res_cursor = type {}
%struct.anon = type { ptr }
; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @xe_migrate_copy(ptr noundef %m, ptr noundef readonly captures(none) %src_bo, ptr noundef readnone captures(address_is_null) %dst_bo, ptr noundef %src, ptr noundef %dst) local_unnamed_addr #0 {
entry:
%src_it = alloca %struct.xe_res_cursor, align 1
%src_L0_ofs = alloca i64, align 8
%dst_L0_ofs = alloca i64, align 8
%src_L0_pt = alloca i32, align 4
%dst_L0_pt = alloca i32, align 4
%src_L0 = alloca i64, align 8
%ccs_ofs = alloca i64, align 8
%ccs_size = alloca i64, align 8
%ccs_pt = alloca i32, align 4
%tmp = alloca %struct.anon, align 8
%tile = getelementptr inbounds nuw i8, ptr %m, i64 8
%0 = load ptr, ptr %tile, align 8, !tbaa !3
%primary_gt = getelementptr inbounds nuw i8, ptr %0, i64 8
%1 = load ptr, ptr %primary_gt, align 8, !tbaa !10
%2 = load ptr, ptr %1, align 8, !tbaa !14
%3 = load ptr, ptr %2, align 8, !tbaa !16
%4 = load i32, ptr %src_bo, align 4, !tbaa !17
call void @llvm.lifetime.start.p0(i64 0, ptr nonnull %src_it) #3
call void @llvm.lifetime.start.p0(i64 0, ptr nonnull %src_it) #3
call void @llvm.lifetime.start.p0(i64 0, ptr nonnull %src_it) #3
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %src_L0_ofs) #3
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %dst_L0_ofs) #3
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %src_L0_pt) #3
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %dst_L0_pt) #3
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %src_L0) #3
%tobool = icmp ne ptr %src, null
%tobool4 = icmp ne ptr %dst, null
%5 = load i32, ptr %src, align 8, !tbaa !20
%tobool6 = icmp ne i32 %5, 0
%6 = load i32, ptr %dst, align 8, !tbaa !20
%tobool9 = icmp ne i32 %6, 0
%tobool13 = icmp ne ptr %3, null
%tobool15 = icmp ne ptr %dst_bo, null
%tobool20.not = icmp eq i32 %4, 0
br i1 %tobool20.not, label %while.end, label %while.body.lr.ph
while.body.lr.ph: ; preds = %entry
%conv60 = zext i1 %tobool13 to i64
br label %while.body
while.body: ; preds = %if.end65, %while.body.lr.ph
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %ccs_ofs) #3
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %ccs_size) #3
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %ccs_pt) #3
%call = call i64 @xe_migrate_res_sizes(ptr noundef %m, ptr noundef nonnull %src_it) #3
%conv23 = trunc i64 %call to i32
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %tmp) #3
call void (ptr, ptr, ...) @__drm_dev_dbg(ptr dead_on_unwind nonnull writable sret(%struct.anon) align 8 %tmp, ptr noundef null, i32 noundef signext 0) #3
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %tmp) #3
%call26 = call zeroext i32 @pte_update_size(ptr noundef %m, i32 noundef zeroext 1, ptr noundef nonnull %src, ptr noundef nonnull %src_it, ptr noundef nonnull %src_L0, ptr noundef nonnull %src_L0_ofs, ptr noundef nonnull %src_L0_pt, i32 noundef zeroext 0, i32 noundef zeroext 0, i32 noundef zeroext %conv23) #3
%call27 = call zeroext i32 @pte_update_size(ptr noundef %m, i32 noundef zeroext 1, ptr noundef nonnull %dst, ptr noundef nonnull %src_it, ptr noundef nonnull %src_L0, ptr noundef nonnull %dst_L0_ofs, ptr noundef nonnull %dst_L0_pt, i32 noundef zeroext 0, i32 noundef zeroext %conv23, i32 noundef zeroext %conv23) #3
br i1 %tobool9, label %if.then, label %if.end
if.then: ; preds = %while.body
%call29 = call zeroext i32 @pte_update_size(ptr noundef %m, i32 noundef zeroext 0, ptr noundef null, ptr noundef nonnull %src_it, ptr noundef nonnull %ccs_size, ptr noundef nonnull %ccs_ofs, ptr noundef nonnull %ccs_pt, i32 noundef zeroext 0, i32 noundef zeroext %conv23, i32 noundef zeroext %conv23) #3
br label %if.end
if.end: ; preds = %if.then, %while.body
%call31 = call ptr @xe_bb_new(ptr noundef nonnull %1, i32 noundef zeroext 2, i1 noundef zeroext %tobool13) #3
%tobool32.not = icmp eq ptr %call31, null
br i1 %tobool32.not, label %if.end34, label %if.end65
if.end34: ; preds = %if.end
%7 = load i32, ptr inttoptr (i64 4 to ptr), align 4, !tbaa !22
br i1 %tobool13, label %if.then36, label %if.end58
if.then36: ; preds = %if.end34
%8 = load i64, ptr %src_L0_ofs, align 8, !tbaa !24
%9 = load i32, ptr %3, align 4, !tbaa !26
%tobool37.not = icmp eq i32 %9, 0
%tobool.tobool6 = select i1 %tobool37.not, i1 %tobool, i1 %tobool6
%10 = load i64, ptr %dst_L0_ofs, align 8, !tbaa !24
%cond53.in = select i1 %tobool37.not, i1 %tobool4, i1 %tobool9
%11 = load i64, ptr %src_L0, align 8, !tbaa !24
%conv55 = trunc i64 %11 to i32
%12 = load i64, ptr %ccs_ofs, align 8, !tbaa !24
%call57 = call zeroext i32 @xe_migrate_ccs_copy(ptr noundef %m, ptr noundef null, i64 noundef %8, i1 noundef zeroext %tobool.tobool6, i64 noundef %10, i1 noundef zeroext %cond53.in, i32 noundef zeroext %conv55, i64 noundef %12, i1 noundef zeroext %tobool15) #3
br label %if.end58
if.end58: ; preds = %if.then36, %if.end34
%13 = load ptr, ptr %m, align 8, !tbaa !29
%call61 = call ptr @xe_bb_create_migration_job(ptr noundef %13, ptr noundef null, i64 noundef %conv60, i32 noundef zeroext %7) #3
br label %if.end65
if.end65: ; preds = %if.end58, %if.end
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %ccs_pt) #3
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %ccs_size) #3
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %ccs_ofs) #3
br label %while.body
while.end: ; preds = %entry
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %src_L0) #3
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %dst_L0_pt) #3
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %src_L0_pt) #3
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %dst_L0_ofs) #3
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %src_L0_ofs) #3
call void @llvm.lifetime.end.p0(i64 0, ptr nonnull %src_it) #3
call void @llvm.lifetime.end.p0(i64 0, ptr nonnull %src_it) #3
call void @llvm.lifetime.end.p0(i64 0, ptr nonnull %src_it) #3
ret ptr null
}
; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr captures(none)) #1
declare i64 @xe_migrate_res_sizes(ptr noundef, ptr noundef) local_unnamed_addr #2
declare void @__drm_dev_dbg(ptr dead_on_unwind writable sret(%struct.anon) align 8, ptr noundef, ...) local_unnamed_addr #2
; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr captures(none)) #1
declare zeroext i32 @pte_update_size(ptr noundef, i32 noundef zeroext, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef zeroext, i32 noundef zeroext, i32 noundef zeroext) local_unnamed_addr #2
declare ptr @xe_bb_new(ptr noundef, i32 noundef zeroext, i1 noundef zeroext) local_unnamed_addr #2
declare zeroext i32 @xe_migrate_ccs_copy(ptr noundef, ptr noundef, i64 noundef, i1 noundef zeroext, i64 noundef, i1 noundef zeroext, i32 noundef zeroext, i64 noundef, i1 noundef zeroext) local_unnamed_addr #2
declare ptr @xe_bb_create_migration_job(ptr noundef, ptr noundef, i64 noundef, i32 noundef zeroext) local_unnamed_addr #2
attributes #0 = { nounwind uwtable "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="ppc64" "target-features"="+64bit,+altivec,+fpu,+fres,+frsqrte,+fsqrt,+hard-float,+mfocrf,+stfiwx" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="ppc64" "target-features"="+64bit,+altivec,+fpu,+fres,+frsqrte,+fsqrt,+hard-float,+mfocrf,+stfiwx" }
attributes #3 = { nounwind }
!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"uwtable", i32 2}
!2 = !{!"ClangBuiltLinux clang version 21.0.0git (https://github.com/llvm/llvm-project.git bf79d4819edeb54c6cf528db63676110992908a8)"}
!3 = !{!4, !9, i64 8}
!4 = !{!"xe_migrate", !5, i64 0, !9, i64 8}
!5 = !{!"p1 _ZTS13xe_exec_queue", !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"p1 _ZTS7xe_tile", !6, i64 0}
!10 = !{!11, !13, i64 8}
!11 = !{!"xe_tile", !12, i64 0, !13, i64 8}
!12 = !{!"p1 _ZTS9xe_device", !6, i64 0}
!13 = !{!"p1 _ZTS5xe_gt", !6, i64 0}
!14 = !{!15, !9, i64 0}
!15 = !{!"xe_gt", !9, i64 0}
!16 = !{!11, !12, i64 0}
!17 = !{!18, !19, i64 0}
!18 = !{!"xe_bo", !19, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = !{!21, !19, i64 0}
!21 = !{!"ttm_resource", !19, i64 0, !5, i64 8}
!22 = !{!23, !19, i64 4}
!23 = !{!"xe_bb", !19, i64 0, !19, i64 4}
!24 = !{!25, !25, i64 0}
!25 = !{!"long", !7, i64 0}
!26 = !{!27, !19, i64 0}
!27 = !{!"xe_device", !28, i64 0}
!28 = !{!"", !19, i64 0}
!29 = !{!4, !5, i64 0}
```
```
$ llc -o /dev/null good-xe_migrate.ll
$ llc -o /dev/null bad-xe_migrate.ll
LLVM ERROR: Found 2 machine code errors.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: llc -o /dev/null bad-xe_migrate.ll
1. Running pass 'Function Pass Manager' on module 'bad-xe_migrate.ll'.
2. Running pass 'PowerPC MI Peephole Optimization' on function '@xe_migrate_copy'
#0 0x000056384e6475a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (llc+0x34ca5a8)
#1 0x000056384e645075 llvm::sys::RunSignalHandlers() (llc+0x34c8075)
#2 0x000056384e647ca1 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f7cbee4def0 (/usr/lib/libc.so.6+0x3def0)
#4 0x00007f7cbeea774c (/usr/lib/libc.so.6+0x9774c)
#5 0x00007f7cbee4ddc0 raise (/usr/lib/libc.so.6+0x3ddc0)
#6 0x00007f7cbee3557a abort (/usr/lib/libc.so.6+0x2557a)
#7 0x000056384e5afa14 llvm::report_fatal_error(llvm::Twine const&, bool) (llc+0x3432a14)
#8 0x000056384d796e3e (llc+0x2619e3e)
#9 0x000056384d7974a6 llvm::MachineFunction::verify(llvm::Pass*, char const*, llvm::raw_ostream*, bool) const (llc+0x261a4a6)
#10 0x000056384cd04c98 (anonymous namespace)::PPCMIPeephole::runOnMachineFunction(llvm::MachineFunction&) PPCMIPeephole.cpp:0:0
#11 0x000056384d667473 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (llc+0x24ea473)
#12 0x000056384dbd1f35 llvm::FPPassManager::runOnFunction(llvm::Function&) (llc+0x2a54f35)
#13 0x000056384dbda102 llvm::FPPassManager::runOnModule(llvm::Module&) (llc+0x2a5d102)
#14 0x000056384dbd298b llvm::legacy::PassManagerImpl::run(llvm::Module&) (llc+0x2a5598b)
#15 0x000056384cb9e386 main (llc+0x1a21386)
#16 0x00007f7cbee376b5 (/usr/lib/libc.so.6+0x276b5)
#17 0x00007f7cbee37769 __libc_start_main (/usr/lib/libc.so.6+0x27769)
#18 0x000056384cb98025 _start (llc+0x1a1b025)
```
The diff of the IR:
```diff
diff --git a/good-xe_migrate.ll b/bad-xe_migrate.ll
index 6222a0e..6632523 100644
--- a/good-xe_migrate.ll
+++ b/bad-xe_migrate.ll
@@ -79,13 +79,13 @@ if.then36: ; preds = %if.end34
%8 = load i64, ptr %src_L0_ofs, align 8, !tbaa !24
%9 = load i32, ptr %3, align 4, !tbaa !26
%tobool37.not = icmp eq i32 %9, 0
- %cond.v = select i1 %tobool37.not, i1 %tobool, i1 %tobool6
+ %tobool.tobool6 = select i1 %tobool37.not, i1 %tobool, i1 %tobool6
%10 = load i64, ptr %dst_L0_ofs, align 8, !tbaa !24
- %cond53.v = select i1 %tobool37.not, i1 %tobool4, i1 %tobool9
+ %cond53.in = select i1 %tobool37.not, i1 %tobool4, i1 %tobool9
%11 = load i64, ptr %src_L0, align 8, !tbaa !24
%conv55 = trunc i64 %11 to i32
%12 = load i64, ptr %ccs_ofs, align 8, !tbaa !24
- %call57 = call zeroext i32 @xe_migrate_ccs_copy(ptr noundef %m, ptr noundef null, i64 noundef %8, i1 noundef zeroext %cond.v, i64 noundef %10, i1 noundef zeroext %cond53.v, i32 noundef zeroext %conv55, i64 noundef %12, i1 noundef zeroext %tobool15) #3
+ %call57 = call zeroext i32 @xe_migrate_ccs_copy(ptr noundef %m, ptr noundef null, i64 noundef %8, i1 noundef zeroext %tobool.tobool6, i64 noundef %10, i1 noundef zeroext %cond53.in, i32 noundef zeroext %conv55, i64 noundef %12, i1 noundef zeroext %tobool15) #3
br label %if.end58
if.end58: ; preds = %if.then36, %if.end34
@@ -129,9 +129,9 @@ declare zeroext i32 @xe_migrate_ccs_copy(ptr noundef, ptr noundef, i64 noundef,
declare ptr @xe_bb_create_migration_job(ptr noundef, ptr noundef, i64 noundef, i32 noundef zeroext) local_unnamed_addr #2
-attributes #0 = { nounwind uwtable "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="ppc64" "target-features"="+altivec,-bpermd,-crbits,-crypto,-direct-move,-extdiv,-htm,-isa-v206-instructions,-isa-v207-instructions,-isa-v30-instructions,-power8-vector,-power9-vector,-privileged,-quadword-atomics,-rop-protect,-spe,-vsx" }
+attributes #0 = { nounwind uwtable "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="ppc64" "target-features"="+64bit,+altivec,+fpu,+fres,+frsqrte,+fsqrt,+hard-float,+mfocrf,+stfiwx" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
-attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="ppc64" "target-features"="+altivec,-bpermd,-crbits,-crypto,-direct-move,-extdiv,-htm,-isa-v206-instructions,-isa-v207-instructions,-isa-v30-instructions,-power8-vector,-power9-vector,-privileged,-quadword-atomics,-rop-protect,-spe,-vsx" }
+attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="ppc64" "target-features"="+64bit,+altivec,+fpu,+fres,+frsqrte,+fsqrt,+hard-float,+mfocrf,+stfiwx" }
attributes #3 = { nounwind }
!llvm.module.flags = !{!0, !1}
@@ -139,7 +139,7 @@ attributes #3 = { nounwind }
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"uwtable", i32 2}
-!2 = !{!"ClangBuiltLinux clang version 21.0.0git (https://github.com/llvm/llvm-project.git 5645d6710904107d66a45f1c3ee0ee25924ff08a)"}
+!2 = !{!"ClangBuiltLinux clang version 21.0.0git (https://github.com/llvm/llvm-project.git bf79d4819edeb54c6cf528db63676110992908a8)"}
!3 = !{!4, !9, i64 8}
!4 = !{!"xe_migrate", !5, i64 0, !9, i64 8}
!5 = !{!"p1 _ZTS13xe_exec_queue", !6, i64 0}
```
https://github.com/llvm/llvm-project/pull/144594
More information about the llvm-commits
mailing list