[LLVMbugs] [Bug 12169] New: reassociation generates unusable code

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Mar 2 16:46:39 PST 2012


http://llvm.org/bugs/show_bug.cgi?id=12169

             Bug #: 12169
           Summary: reassociation generates unusable code
           Product: new-bugs
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: kmacy at freebsd.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


This is the ocaml code in the test function:
let rec f x0 =
  let x1 = x0 + 1 in
  let x2 = x1 + 1 in
  let x3 = x2 + 1 in
  let x4 = x3 + 1 in
  let x5 = x4 + 1 in
  let x6 = x5 + 1 in
  let x7 = x6 + 1 in
  let x8 = x7 + 1 in
  let x9 = x8 + 1 in
  let x10 = x9 + 1 in
  let x11 = x10 + 1 in
  let x12 = x11 + 1 in
  let x13 = x12 + 1 in
  let x14 = x13 + 1 in
  let x15 = x14 + 1 in
  let x16 = x15 + 1 in
  let x17 = x16 + 1 in
  let x18 = x17 + 1 in
  let x19 = x18 + x1 in
  let x20 = x19 + x2 in
  let x21 = x20 + x3 in
  let x22 = x21 + x4 in
  let x23 = x22 + x5 in
  let x24 = x23 + x6 in
  let x25 = x24 + x7 in
  let x26 = x25 + x8 in
  let x27 = x26 + x9 in
  let x28 = x27 + x10 in
  let x29 = x28 + x11 in
  let x30 = x29 + x12 in
  let x31 = x30 + x13 in
  let x32 = x31 + x14 in
  let x33 = x32 + x15 in
  let x34 = x33 + x16 in
  let x35 = x34 + x17 in
  let x36 = x35 + x0 in
  x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + 
    x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 +
    x20 + x21 + x22 + x23 + x24 + x25 + x26 + x27 + x28 + x29 +
    x30 + x31 + x32 + x33 + x34 + x35 + x36 + x0 in
print_int (f 0)

This is the IR code generated by the backend and the passes preceeding
reassociation:


m is :; ModuleID = 'test/spill3'

define fastcc i64 @f(i64 %x0) {
entry:
  %0 = add i64 %x0, 1
  %1 = add i64 %x0, 2
  %2 = add i64 %x0, 3
  %3 = add i64 %x0, 4
  %4 = add i64 %x0, 5
  %5 = add i64 %x0, 6
  %6 = add i64 %x0, 7
  %7 = add i64 %x0, 8
  %8 = add i64 %x0, 9
  %9 = add i64 %x0, 10
  %10 = add i64 %x0, 11
  %11 = add i64 %x0, 12
  %12 = add i64 %x0, 13
  %13 = add i64 %x0, 14
  %14 = add i64 %x0, 15
  %15 = add i64 %x0, 16
  %16 = add i64 %x0, 17
  %17 = add i64 %x0, 18
  %18 = add i64 %17, %0
  %19 = add i64 %18, %1
  %20 = add i64 %19, %2
  %21 = add i64 %20, %3
  %22 = add i64 %21, %4
  %23 = add i64 %22, %5
  %24 = add i64 %23, %6
  %25 = add i64 %24, %7
  %26 = add i64 %25, %8
  %27 = add i64 %26, %9
  %28 = add i64 %27, %10
  %29 = add i64 %28, %11
  %30 = add i64 %29, %12
  %31 = add i64 %30, %13
  %32 = add i64 %31, %14
  %33 = add i64 %32, %15
  %34 = add i64 %33, %16
  %35 = add i64 %34, %x0
  %36 = add i64 %0, %1
  %37 = add i64 %36, %2
  %38 = add i64 %37, %3
  %39 = add i64 %38, %4
  %40 = add i64 %39, %5
  %41 = add i64 %40, %6
  %42 = add i64 %41, %7
  %43 = add i64 %42, %8
  %44 = add i64 %43, %9
  %45 = add i64 %44, %10
  %46 = add i64 %45, %11
  %47 = add i64 %46, %12
  %48 = add i64 %47, %13
  %49 = add i64 %48, %14
  %50 = add i64 %49, %15
  %51 = add i64 %50, %16
  %52 = add i64 %51, %17
  %53 = add i64 %52, %18
  %54 = add i64 %53, %19
  %55 = add i64 %54, %20
  %56 = add i64 %55, %21
  %57 = add i64 %56, %22
  %58 = add i64 %57, %23
  %59 = add i64 %58, %24
  %60 = add i64 %59, %25
  %61 = add i64 %60, %26
  %62 = add i64 %61, %27
  %63 = add i64 %62, %28
  %64 = add i64 %63, %29
  %65 = add i64 %64, %30
  %66 = add i64 %65, %31
  %67 = add i64 %66, %32
  %68 = add i64 %67, %33
  %69 = add i64 %68, %34
  %70 = add i64 %69, %35
  %71 = add i64 %70, %x0
  ret i64 %71
}

define void @main() {
entry:
  %0 = call fastcc i64 @f(i64 0)
  call void @print_int(i64 %0)
  ret void
}

declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32,
i1) nounwind

declare void @print_int(i64)


This gives the correct result:
1617


This is the output of the reassociation pass for this IR:


m is :; ModuleID = 'test/spill3'

define fastcc i64 @f(i64 %x0) {
entry:
  %0 = add i64 undef, undef
  %1 = add i64 %0, undef
  %2 = add i64 %1, undef
  %3 = add i64 %2, undef
  %4 = add i64 %3, undef
  %5 = add i64 %4, undef
  %6 = add i64 %5, undef
  %7 = add i64 %6, undef
  %8 = add i64 %7, undef
  %9 = add i64 %8, undef
  %10 = add i64 %9, undef
  %11 = add i64 %10, undef
  %12 = add i64 %11, undef
  %13 = add i64 %12, undef
  %14 = add i64 %13, undef
  %15 = add i64 %14, undef
  %16 = add i64 %15, undef
  %17 = add i64 %16, undef
  %18 = add i64 %17, undef
  %19 = add i64 %18, undef
  %20 = add i64 %19, undef
  %21 = add i64 %20, undef
  %22 = add i64 %21, undef
  %23 = add i64 %22, undef
  %24 = add i64 %23, undef
  %25 = add i64 %24, undef
  %26 = add i64 %25, undef
  %27 = add i64 %26, undef
  %28 = add i64 %27, undef
  %29 = add i64 %28, undef
  %30 = add i64 %29, undef
  %31 = add i64 %30, undef
  %32 = add i64 %31, undef
  %33 = add i64 %32, undef
  %factor94 = mul i64 %x0, 19
  %tmp = add i64 %factor94, 171
  %tmp95 = mul i64 %tmp, 2
  %34 = add i64 %33, %0
  %35 = add i64 %34, %31
  %36 = add i64 %35, %29
  %37 = add i64 %36, %27
  %38 = add i64 %37, %25
  %39 = add i64 %38, %23
  %40 = add i64 %39, %21
  %41 = add i64 %40, %19
  %42 = add i64 %41, %17
  %43 = add i64 %42, %15
  %44 = add i64 %43, %13
  %45 = add i64 %44, %11
  %46 = add i64 %45, %9
  %47 = add i64 %46, %7
  %48 = add i64 %47, %5
  %49 = add i64 %48, %3
  %50 = add i64 %49, %1
  %51 = add i64 %50, %2
  %52 = add i64 %51, %4
  %53 = add i64 %52, %6
  %54 = add i64 %53, %8
  %55 = add i64 %54, %10
  %56 = add i64 %55, %12
  %57 = add i64 %56, %14
  %58 = add i64 %57, %16
  %59 = add i64 %58, %18
  %60 = add i64 %59, %20
  %61 = add i64 %60, %22
  %62 = add i64 %61, %24
  %63 = add i64 %62, %26
  %64 = add i64 %63, %28
  %65 = add i64 %64, %30
  %66 = add i64 %65, %32
  %67 = add i64 %66, %tmp95
  ret i64 %67
}

define void @main() {
entry:
  %0 = call fastcc i64 @f(i64 0)
  call void @print_int(i64 %0)
  ret void
}

declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32,
i1) nounwind

declare void @print_int(i64)

It gives the wrong result:

-129449968

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list