[LLVMdev] Code generators (both llvmc and Jit) get stuck when dealing circular CFG

Gabi bugspynet at gmail.com
Sun Apr 4 15:55:01 PDT 2010


Hi,
The following arbitrary example makes the code generators to get stuck
(llvmc won't return from command line, Jit won't return from function
call)
Basically it is a CFG with circles, (the function will return by
comparing a branch counter to a threshold on runtime - see the
"Brancher" blocks below)
Any idea what goes wrong? Is it a bug in llvm ?

; ModuleID = 'TestModule!'

define double @fn1(i8*, i64) {
Entry:
  %BranchCounter = alloca i32                     ; <i32*> [#uses=7]
  store i32 0, i32* %BranchCounter
  %Vars = alloca double, i32 3                    ; <double*> [#uses=3]
  %DoubleVar = getelementptr inbounds double* %Vars, i32 0 ; <double*> [#uses=6]
  store double 0xC031AD5A40000000, double* %DoubleVar
  %DoubleVar1 = getelementptr inbounds double* %Vars, i32 1 ;
<double*> [#uses=1]
  store double 0xC055A9E9E0000000, double* %DoubleVar1
  %DoubleVar2 = getelementptr inbounds double* %Vars, i32 2 ;
<double*> [#uses=4]
  store double 0xC0495B8A80000000, double* %DoubleVar2
  br label %Brancher

Exit:                                             ; preds =
%Brancher7, %Brancher4, %Brancher
  %2 = load double* %DoubleVar                    ; <double> [#uses=1]
  ret double %2

Body:                                             ; preds = %Brancher
  %3 = srem i64 30, %1                            ; <i64> [#uses=1]
  %4 = getelementptr inbounds i8* %0, i64 %3      ; <i8*> [#uses=1]
  %5 = load i8* %4                                ; <i8> [#uses=1]
  %PeekResult = uitofp i8 %5 to double            ; <double> [#uses=0]
  %6 = load double* %DoubleVar2                   ; <double> [#uses=1]
  store double 0x40619C4E80000000, double* %DoubleVar
  %7 = srem i64 178, %1                           ; <i64> [#uses=1]
  %8 = getelementptr inbounds i8* %0, i64 %7      ; <i8*> [#uses=1]
  %9 = load i8* %8                                ; <i8> [#uses=1]
  %PeekResult9 = uitofp i8 %9 to double           ; <double> [#uses=0]
  store double %6, double* %DoubleVar
  %10 = load double* %DoubleVar2                  ; <double> [#uses=0]
  %11 = load double* %DoubleVar                   ; <double> [#uses=0]
  br i1 false, label %Brancher7, label %Brancher4

Brancher:                                         ; preds = %Entry
  %12 = load i32* %BranchCounter                  ; <i32> [#uses=1]
  %"BrCounter++" = add i32 %12, 1                 ; <i32> [#uses=2]
  store i32 %"BrCounter++", i32* %BranchCounter
  %13 = icmp ult i32 %"BrCounter++", 10           ; <i1> [#uses=1]
  br i1 %13, label %Body, label %Exit

Body3:                                            ; preds = %Brancher4
  %14 = srem i64 40, %1                           ; <i64> [#uses=1]
  %15 = getelementptr inbounds i8* %0, i64 %14    ; <i8*> [#uses=1]
  %16 = load i8* %15                              ; <i8> [#uses=1]
  %PeekResult10 = uitofp i8 %16 to double         ; <double> [#uses=2]
  %17 = fsub double 0xC058173FC0000000, %PeekResult10 ; <double> [#uses=1]
  store double %PeekResult10, double* %DoubleVar2
  %18 = fsub double 0x406AB76488000000, %17       ; <double> [#uses=1]
  %19 = fdiv double %18, 0x4068C87680000000       ; <double> [#uses=0]
  br label %Brancher4

Brancher4:                                        ; preds = %Body6,
%Body3, %Body
  %20 = load i32* %BranchCounter                  ; <i32> [#uses=1]
  %"BrCounter++5" = add i32 %20, 1                ; <i32> [#uses=2]
  store i32 %"BrCounter++5", i32* %BranchCounter
  %21 = icmp ult i32 %"BrCounter++5", 10          ; <i1> [#uses=1]
  br i1 %21, label %Body3, label %Exit

Body6:                                            ; preds = %Brancher7
  %22 = load double* %DoubleVar                   ; <double> [#uses=3]
  %23 = srem i64 7118, %1                         ; <i64> [#uses=1]
  %24 = getelementptr inbounds i8* %0, i64 %23    ; <i8*> [#uses=1]
  %25 = load i8* %24                              ; <i8> [#uses=1]
  %PeekResult11 = uitofp i8 %25 to double         ; <double> [#uses=0]
  %26 = fsub double %22, %22                      ; <double> [#uses=0]
  %27 = fcmp oeq double 0xC04FBB2E40000000, %22   ; <i1> [#uses=1]
  br i1 %27, label %Brancher4, label %Brancher7

Brancher7:                                        ; preds = %Body6, %Body
  %28 = load i32* %BranchCounter                  ; <i32> [#uses=1]
  %"BrCounter++8" = add i32 %28, 1                ; <i32> [#uses=2]
  store i32 %"BrCounter++8", i32* %BranchCounter
  %29 = icmp ult i32 %"BrCounter++8", 10          ; <i1> [#uses=1]
  br i1 %29, label %Body6, label %Exit
}


-- 
Regards,
Gabi

http://bugspy.net



More information about the llvm-dev mailing list