-instcombine broken with fastcall

I found this with LLVM 2.3 and reproduced with svn as of about thirty
minutes ago and they both fail in the same way.

If you run this code through opt -instcombine

define fastcc i64 @fibo(i64) {
  switch i64 %0, label %2 [
    i64 0, label %8
    i64 1, label %8
  ]

; <label>:2 ; preds = %1
  %3 = sub i64 %0, 1 ; <i64> [#uses=1]
  %4 = call i64 @fibo(i64 %3) ; <i64> [#uses=1]
  %5 = sub i64 %0, 2 ; <i64> [#uses=1]
  %6 = call i64 @fibo(i64 %5) ; <i64> [#uses=1]
  %7 = add i64 %4, %6 ; <i64> [#uses=1]
  ret i64 %7

; <label>:8 ; preds = %1, %1
  ret i64 1
}

you get this crap back

define fastcc i64 @fibo(i64) {
  switch i64 %0, label %2 [
    i64 0, label %4
    i64 1, label %4
  ]

; <label>:2 ; preds = %1
  store i1 true, i1* undef
  store i1 true, i1* undef
  %3 = add i64 undef, undef ; <i64> [#uses=1]
  ret i64 %3

; <label>:4 ; preds = %1, %1
  ret i64 1
}

(which, called in a program gives an instant bus error)

Arnaud

Your input code has undefined behavior. You have to mark the callsite as fastcc also.

-Chris

I found this with LLVM 2.3 and reproduced with svn as of about thirty
minutes ago and they both fail in the same way.

If you run this code through opt -instcombine

Your input code has undefined behavior. You have to mark the callsite
as fastcc also.

Thanks. I didn't know that.

Arnaud