Skip to content
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

[AArch64] UNREACHABLE executed at AArch64ISelLowering.cpp:6144 #83555

Closed
tblah opened this issue Mar 1, 2024 · 4 comments · Fixed by #70267
Closed

[AArch64] UNREACHABLE executed at AArch64ISelLowering.cpp:6144 #83555

tblah opened this issue Mar 1, 2024 · 4 comments · Fixed by #70267

Comments

@tblah
Copy link
Contributor

tblah commented Mar 1, 2024

LLVM version: 199bbe2

Compiling https://github.com/llvm/llvm-test-suite/blob/main/Fortran/gfortran/regression/internal_dummy_3.f08 with llvm-flang leads to a crash from hitting UNREACHABLE at AArch64ISelLowering.cpp:6144.

LLVM IR generated by flang:

; ModuleID = 'internal_dummy_3.ll'
source_filename = "FIRModule"
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-linux-gnu"

@_QMmEfirst = global ptr null
@_QQEnvironmentDefaults = constant ptr null

define void @_QMmPtest(ptr %0, ptr %1, ptr %2) #0 {
  %4 = alloca i32, i64 1, align 4
  %5 = alloca i32, i64 1, align 4
  %6 = alloca { ptr }, i64 1, align 8
  %7 = getelementptr { ptr }, ptr %6, i32 0, i32 0
  store ptr %0, ptr %7, align 8
  %8 = ptrtoint ptr %1 to i64
  %9 = icmp ne i64 %8, 0
  br i1 %9, label %10, label %17

10:                                               ; preds = %3
  %11 = call i32 %1()
  %12 = load i32, ptr %0, align 4
  %13 = sub i32 %12, 1
  %14 = icmp ne i32 %11, %13
  br i1 %14, label %15, label %17

15:                                               ; preds = %10
  %16 = call {} @_FortranAStopStatement(i32 1, i1 false, i1 false)
  unreachable

17:                                               ; preds = %10, %3
  %18 = ptrtoint ptr %2 to i64
  %19 = icmp ne i64 %18, 0
  br i1 %19, label %20, label %27

20:                                               ; preds = %17
  %21 = call i32 %2()
  %22 = load i32, ptr %0, align 4
  %23 = sub i32 %22, 2
  %24 = icmp ne i32 %21, %23
  br i1 %24, label %25, label %27

25:                                               ; preds = %20
  %26 = call {} @_FortranAStopStatement(i32 2, i1 false, i1 false)
  unreachable

27:                                               ; preds = %20, %17
  %28 = load i32, ptr %0, align 4
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %33

30:                                               ; preds = %27
  %31 = alloca [32 x i8], i64 1, align 4
  call void @llvm.init.trampoline(ptr %31, ptr @_QMmFtestPmylevel, ptr %6)
  %32 = call ptr @llvm.adjust.trampoline(ptr %31)
  store ptr %32, ptr @_QMmEfirst, align 8
  br label %33

33:                                               ; preds = %30, %27
  %34 = load ptr, ptr @_QMmEfirst, align 8
  %35 = call i32 %34()
  %36 = icmp ne i32 %35, 1
  br i1 %36, label %37, label %39

37:                                               ; preds = %33
  %38 = call {} @_FortranAStopStatement(i32 3, i1 false, i1 false)
  unreachable

39:                                               ; preds = %33
  %40 = load i32, ptr %0, align 4
  %41 = icmp eq i32 %40, 10
  br i1 %41, label %53, label %42

42:                                               ; preds = %39
  br i1 %9, label %43, label %48

43:                                               ; preds = %42
  %44 = load i32, ptr %0, align 4
  %45 = add i32 %44, 1
  %46 = alloca [32 x i8], i64 1, align 4
  call void @llvm.init.trampoline(ptr %46, ptr @_QMmFtestPmylevel, ptr %6)
  %47 = call ptr @llvm.adjust.trampoline(ptr %46)
  store i32 %45, ptr %5, align 4
  call void @_QMmPtest(ptr %5, ptr %47, ptr %1)
  br label %53

48:                                               ; preds = %42
  %49 = load i32, ptr %0, align 4
  %50 = add i32 %49, 1
  %51 = alloca [32 x i8], i64 1, align 4
  call void @llvm.init.trampoline(ptr %51, ptr @_QMmFtestPmylevel, ptr %6)
  %52 = call ptr @llvm.adjust.trampoline(ptr %51)
  store i32 %50, ptr %4, align 4
  call void @_QMmPtest(ptr %4, ptr %52, ptr null)
  br label %53

53:                                               ; preds = %48, %43, %39
  ret void
}

define internal i32 @_QMmFtestPmylevel(ptr nest %0) #0 {
  %2 = getelementptr { ptr }, ptr %0, i32 0, i32 0
  %3 = load ptr, ptr %2, align 8
  %4 = alloca i32, i64 1, align 4
  %5 = load i32, ptr %3, align 4
  store i32 %5, ptr %4, align 4
  %6 = load i32, ptr %4, align 4
  ret i32 %6
}

define void @_QQmain() #0 {
  %1 = alloca i32, i64 1, align 4
  store i32 1, ptr %1, align 4
  call void @_QMmPtest(ptr %1, ptr null, ptr null)
  ret void
}

declare {} @_FortranAStopStatement(i32, i1 zeroext, i1 zeroext)

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.init.trampoline(ptr nocapture writeonly, ptr readnone, ptr readnone) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: read)
declare ptr @llvm.adjust.trampoline(ptr) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

attributes #0 = { "frame-pointer"="non-leaf" "target-cpu"="generic" "target-features"="+outline-atomics,+v8a,+fp-armv8,+neon" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: read) }
attributes #3 = { nocallback nofree nosync nounwind willreturn }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}

To reproduce, run llc on this IR.

@llvmbot
Copy link
Member

llvmbot commented Mar 1, 2024

@llvm/issue-subscribers-backend-aarch64

Author: Tom Eccles (tblah)

LLVM version: 199bbe2

Compiling https://github.com/llvm/llvm-test-suite/blob/main/Fortran/gfortran/regression/internal_dummy_3.f08 with llvm-flang leads to a crash from hitting UNREACHABLE at AArch64ISelLowering.cpp:6144.

LLVM IR generated by flang:

; ModuleID = 'internal_dummy_3.ll'
source_filename = "FIRModule"
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-linux-gnu"

@<!-- -->_QMmEfirst = global ptr null
@<!-- -->_QQEnvironmentDefaults = constant ptr null

define void @<!-- -->_QMmPtest(ptr %0, ptr %1, ptr %2) #<!-- -->0 {
  %4 = alloca i32, i64 1, align 4
  %5 = alloca i32, i64 1, align 4
  %6 = alloca { ptr }, i64 1, align 8
  %7 = getelementptr { ptr }, ptr %6, i32 0, i32 0
  store ptr %0, ptr %7, align 8
  %8 = ptrtoint ptr %1 to i64
  %9 = icmp ne i64 %8, 0
  br i1 %9, label %10, label %17

10:                                               ; preds = %3
  %11 = call i32 %1()
  %12 = load i32, ptr %0, align 4
  %13 = sub i32 %12, 1
  %14 = icmp ne i32 %11, %13
  br i1 %14, label %15, label %17

15:                                               ; preds = %10
  %16 = call {} @<!-- -->_FortranAStopStatement(i32 1, i1 false, i1 false)
  unreachable

17:                                               ; preds = %10, %3
  %18 = ptrtoint ptr %2 to i64
  %19 = icmp ne i64 %18, 0
  br i1 %19, label %20, label %27

20:                                               ; preds = %17
  %21 = call i32 %2()
  %22 = load i32, ptr %0, align 4
  %23 = sub i32 %22, 2
  %24 = icmp ne i32 %21, %23
  br i1 %24, label %25, label %27

25:                                               ; preds = %20
  %26 = call {} @<!-- -->_FortranAStopStatement(i32 2, i1 false, i1 false)
  unreachable

27:                                               ; preds = %20, %17
  %28 = load i32, ptr %0, align 4
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %33

30:                                               ; preds = %27
  %31 = alloca [32 x i8], i64 1, align 4
  call void @<!-- -->llvm.init.trampoline(ptr %31, ptr @<!-- -->_QMmFtestPmylevel, ptr %6)
  %32 = call ptr @<!-- -->llvm.adjust.trampoline(ptr %31)
  store ptr %32, ptr @<!-- -->_QMmEfirst, align 8
  br label %33

33:                                               ; preds = %30, %27
  %34 = load ptr, ptr @<!-- -->_QMmEfirst, align 8
  %35 = call i32 %34()
  %36 = icmp ne i32 %35, 1
  br i1 %36, label %37, label %39

37:                                               ; preds = %33
  %38 = call {} @<!-- -->_FortranAStopStatement(i32 3, i1 false, i1 false)
  unreachable

39:                                               ; preds = %33
  %40 = load i32, ptr %0, align 4
  %41 = icmp eq i32 %40, 10
  br i1 %41, label %53, label %42

42:                                               ; preds = %39
  br i1 %9, label %43, label %48

43:                                               ; preds = %42
  %44 = load i32, ptr %0, align 4
  %45 = add i32 %44, 1
  %46 = alloca [32 x i8], i64 1, align 4
  call void @<!-- -->llvm.init.trampoline(ptr %46, ptr @<!-- -->_QMmFtestPmylevel, ptr %6)
  %47 = call ptr @<!-- -->llvm.adjust.trampoline(ptr %46)
  store i32 %45, ptr %5, align 4
  call void @<!-- -->_QMmPtest(ptr %5, ptr %47, ptr %1)
  br label %53

48:                                               ; preds = %42
  %49 = load i32, ptr %0, align 4
  %50 = add i32 %49, 1
  %51 = alloca [32 x i8], i64 1, align 4
  call void @<!-- -->llvm.init.trampoline(ptr %51, ptr @<!-- -->_QMmFtestPmylevel, ptr %6)
  %52 = call ptr @<!-- -->llvm.adjust.trampoline(ptr %51)
  store i32 %50, ptr %4, align 4
  call void @<!-- -->_QMmPtest(ptr %4, ptr %52, ptr null)
  br label %53

53:                                               ; preds = %48, %43, %39
  ret void
}

define internal i32 @<!-- -->_QMmFtestPmylevel(ptr nest %0) #<!-- -->0 {
  %2 = getelementptr { ptr }, ptr %0, i32 0, i32 0
  %3 = load ptr, ptr %2, align 8
  %4 = alloca i32, i64 1, align 4
  %5 = load i32, ptr %3, align 4
  store i32 %5, ptr %4, align 4
  %6 = load i32, ptr %4, align 4
  ret i32 %6
}

define void @<!-- -->_QQmain() #<!-- -->0 {
  %1 = alloca i32, i64 1, align 4
  store i32 1, ptr %1, align 4
  call void @<!-- -->_QMmPtest(ptr %1, ptr null, ptr null)
  ret void
}

declare {} @<!-- -->_FortranAStopStatement(i32, i1 zeroext, i1 zeroext)

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @<!-- -->llvm.init.trampoline(ptr nocapture writeonly, ptr readnone, ptr readnone) #<!-- -->1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: read)
declare ptr @<!-- -->llvm.adjust.trampoline(ptr) #<!-- -->2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @<!-- -->llvm.stacksave.p0() #<!-- -->3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @<!-- -->llvm.stackrestore.p0(ptr) #<!-- -->3

attributes #<!-- -->0 = { "frame-pointer"="non-leaf" "target-cpu"="generic" "target-features"="+outline-atomics,+v8a,+fp-armv8,+neon" }
attributes #<!-- -->1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #<!-- -->2 = { nocallback nofree nosync nounwind willreturn memory(argmem: read) }
attributes #<!-- -->3 = { nocallback nofree nosync nounwind willreturn }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}

To reproduce, run llc on this IR.

@davemgreen
Copy link
Collaborator

This might need #70267

@tblah
Copy link
Contributor Author

tblah commented Mar 11, 2024

Yes that fixes this, thanks

@ceseo
Copy link
Contributor

ceseo commented Mar 12, 2024

@davemgreen do you want me to put a warning in this code path? It's the third issue opened against this and my patch won't be merged for the reasons discussed in the 01/08 Flang call.

ceseo added a commit to ceseo/llvm-project that referenced this issue Jul 15, 2024
Add support for llvm.init.trampoline and llvm.adjust.trampoline intrinsics for
AArch64.

Fixes llvm#65573
Fixes llvm#76927
Fixes llvm#83555
Updates llvm#66157
ceseo added a commit to ceseo/llvm-project that referenced this issue Jul 16, 2024
Add support for llvm.init.trampoline and llvm.adjust.trampoline intrinsics for
AArch64.

Fixes llvm#65573
Fixes llvm#76927
Fixes llvm#83555
Updates llvm#66157
ceseo added a commit to ceseo/llvm-project that referenced this issue Jul 16, 2024
Add support for llvm.init.trampoline and llvm.adjust.trampoline intrinsics for
AArch64.

Fixes llvm#65573
Fixes llvm#76927
Fixes llvm#83555
Updates llvm#66157
ceseo added a commit to ceseo/llvm-project that referenced this issue Jul 23, 2024
Add support for llvm.init.trampoline and llvm.adjust.trampoline intrinsics for
AArch64.

Fixes llvm#65573
Fixes llvm#76927
Fixes llvm#83555
Updates llvm#66157
ceseo added a commit to ceseo/llvm-project that referenced this issue Jul 23, 2024
Add support for llvm.init.trampoline and llvm.adjust.trampoline intrinsics for
AArch64.

Fixes llvm#65573
Fixes llvm#76927
Fixes llvm#83555
Updates llvm#66157
ceseo added a commit to ceseo/llvm-project that referenced this issue Jul 24, 2024
Add support for llvm.init.trampoline and llvm.adjust.trampoline intrinsics for
AArch64.

Fixes llvm#65573
Fixes llvm#76927
Fixes llvm#83555
Updates llvm#66157
@ceseo ceseo closed this as completed in c4b66bf Jul 24, 2024
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Jul 24, 2024
Add support for llvm.init.trampoline and llvm.adjust.trampoline
intrinsics for AArch64.

Fixes llvm#65573
Fixes llvm#76927
Fixes llvm#83555
Updates llvm#66157

(cherry picked from commit c4b66bf)
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Jul 24, 2024
Add support for llvm.init.trampoline and llvm.adjust.trampoline
intrinsics for AArch64.

Fixes llvm#65573
Fixes llvm#76927
Fixes llvm#83555
Updates llvm#66157

(cherry picked from commit c4b66bf)
yuxuanchen1997 pushed a commit that referenced this issue Jul 25, 2024
Summary:
Add support for llvm.init.trampoline and llvm.adjust.trampoline
intrinsics for AArch64.

Fixes #65573
Fixes #76927
Fixes #83555
Updates #66157

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250624
tru pushed a commit to llvmbot/llvm-project that referenced this issue Jul 26, 2024
Add support for llvm.init.trampoline and llvm.adjust.trampoline
intrinsics for AArch64.

Fixes llvm#65573
Fixes llvm#76927
Fixes llvm#83555
Updates llvm#66157

(cherry picked from commit c4b66bf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants