[LLVMbugs] [Bug 7876] New: ipsccp change return value to undef without reason

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Aug 12 09:39:28 PDT 2010


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

           Summary: ipsccp change return value to undef without reason
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Interprocedural Optimizations
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: quickslyver at free.fr
                CC: llvmbugs at cs.uiuc.edu


from gcc torture suite:

------------------------------------------------------------------------
reproducer:

-----------------------------------------------
$cat pr34768-2.c
int x;

int __attribute__((noinline)) foo (void)
{
  x = -x;
  return 0;
}
int __attribute__((const,noinline)) bar (void)
{
  return 0;
}

int __attribute__((noinline))
test (int c)
{
  int tmp = x;
  int res = (c ? foo : bar) ();
  return tmp + x + res;
}

extern void abort (void);
int main()
{
  x = 1;
  if (test (1) != 0)
    abort ();
  return 0;
}

$clang -O3 pr34768-2.c -c -emit-llvm -o test.bc
$opt test.bc -internalize -ipsccp -o bug.bc

$llvm-dis test.bc
[...]
define i32 @foo() nounwind noinline {
entry:
  %tmp = load i32* @x, align 4                    ; <i32> [#uses=1]
  %sub = sub nsw i32 0, %tmp                      ; <i32> [#uses=1]
  store i32 %sub, i32* @x, align 4
  ret i32 0
}
[...]
define i32 @test(i32 %c) nounwind noinline {
entry:
  %tmp1 = load i32* @x, align 4                   ; <i32> [#uses=1]
  %tobool = icmp ne i32 %c, 0                     ; <i1> [#uses=1]
  %cond = select i1 %tobool, i32 ()* @foo, i32 ()* @bar ; <i32 ()*> [#uses=1]
  %call = tail call i32 %cond() nounwind          ; <i32> [#uses=1]
  %tmp5 = load i32* @x, align 4                   ; <i32> [#uses=1]
  %add = add nsw i32 %call, %tmp1                 ; <i32> [#uses=1]
  %add7 = add nsw i32 %add, %tmp5                 ; <i32> [#uses=1]
  ret i32 %add7
}

[...]

$llvm-dis bug.bc
[...]
define internal i32 @foo() nounwind noinline {
entry:
  %tmp = load i32* @x, align 4                    ; <i32> [#uses=1]
  %sub = sub nsw i32 0, %tmp                      ; <i32> [#uses=1]
  store i32 %sub, i32* @x, align 4
  ret i32 undef
}
[...]
define internal i32 @test(i32 %c) nounwind noinline {
entry:
  %tmp1 = load i32* @x, align 4                   ; <i32> [#uses=1]
  %call = tail call i32 @foo() nounwind           ; <i32> [#uses=1]
  %tmp5 = load i32* @x, align 4                   ; <i32> [#uses=1]
  %add = add nsw i32 %call, %tmp1                 ; <i32> [#uses=1]
  %add7 = add nsw i32 %add, %tmp5                 ; <i32> [#uses=1]
  ret i32 %add7
}
[...]


-------------------------------------------------------------------------------
Comments:
after internalize and ipsccp passes function "foo" returns "undef" instead of
"0" BUT this result is used by function "test" then the test fails.

-- 
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