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

llc cannot be verified defer in phi #907

Open
visualfc opened this issue Dec 5, 2024 · 1 comment
Open

llc cannot be verified defer in phi #907

visualfc opened this issue Dec 5, 2024 · 1 comment

Comments

@visualfc
Copy link
Member

visualfc commented Dec 5, 2024

main.go

package main

func check() {}

func demo(n int) bool {
	defer check()
	var b bool
	if n == 100 {
		b = true
	} else {
		b = false
	}
	return b
}

func main() {
	demo(1)
}

ssa

func demo(n int) bool:
0:                                                                entry P:0 S:2
	defer check()
	t0 = n == 100:int                                                  bool
	if t0 goto 2 else 4
1:                                                              recover P:0 S:0
	return false:bool
2:                                                              if.then P:1 S:1
	jump 3
3:                                                              if.done P:2 S:0
	t1 = phi [2: true:bool, 4: false:bool] #b                          bool
	rundefers
	return t1
4:                                                              if.else P:1 S:1
	jump 3

main.ll

define i1 @main.demo(i64 %0) {
_llgo_0:
  %1 = load i32, ptr @__llgo_defer, align 4
  %2 = call ptr @pthread_getspecific(i32 %1)
  %3 = alloca i8, i64 152, align 1
  %4 = alloca i8, i64 40, align 1
  %5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 0
  store ptr %3, ptr %5, align 8
  %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 1
  store i64 0, ptr %6, align 4
  %7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 2
  store ptr %2, ptr %7, align 8
  %8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 3
  store ptr blockaddress(@main.demo, %_llgo_5), ptr %8, align 8
  %9 = call i32 @pthread_setspecific(i32 %1, ptr %4)
  %10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 1
  %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 3
  %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 4
  %13 = call i32 @sigsetjmp(ptr %3, i32 0)
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %_llgo_7, label %_llgo_8

_llgo_1:                                          ; preds = %_llgo_6
  ret i1 false

_llgo_2:                                          ; preds = %_llgo_7
  br label %_llgo_3

_llgo_3:                                          ; preds = %_llgo_4, %_llgo_2
  %15 = phi i1 [ true, %_llgo_2 ], [ false, %_llgo_4 ]
  store ptr blockaddress(@main.demo, %_llgo_9), ptr %12, align 8
  br label %_llgo_5

_llgo_4:                                          ; preds = %_llgo_7
  br label %_llgo_3

_llgo_5:                                          ; preds = %_llgo_8, %_llgo_3
  store ptr blockaddress(@main.demo, %_llgo_6), ptr %11, align 8
  %16 = load i64, ptr %10, align 4
  call void @main.check()
  %17 = load %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, align 8
  %18 = extractvalue %"github.com/goplus/llgo/internal/runtime.Defer" %17, 2
  %19 = call i32 @pthread_setspecific(i32 %1, ptr %18)
  %20 = load ptr, ptr %12, align 8
  indirectbr ptr %20, [label %_llgo_6, label %_llgo_9]

_llgo_6:                                          ; preds = %_llgo_8, %_llgo_5
  call void @"github.com/goplus/llgo/internal/runtime.Rethrow"(ptr %2)
  br label %_llgo_1

_llgo_7:                                          ; preds = %_llgo_0
  %21 = icmp eq i64 %0, 100
  br i1 %21, label %_llgo_2, label %_llgo_4

_llgo_8:                                          ; preds = %_llgo_0
  store ptr blockaddress(@main.demo, %_llgo_6), ptr %12, align 8
  %22 = load ptr, ptr %11, align 8
  indirectbr ptr %22, [label %_llgo_6, label %_llgo_5]

_llgo_9:                                          ; preds = %_llgo_5
  ret i1 %15
}

llc main.ll

Instruction does not dominate all uses!
  %15 = phi i1 [ true, %_llgo_2 ], [ false, %_llgo_4 ]
  ret i1 %15
@cpunion
Copy link
Contributor

cpunion commented Jan 4, 2025

Related: #802

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants