[LLVMbugs] [Bug 21514] New: compiler-rt/lib/builtins/muldi3.c: Infinite loop/stack overflow in __muldi3

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Nov 7 06:34:37 PST 2014


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

            Bug ID: 21514
           Summary: compiler-rt/lib/builtins/muldi3.c:  Infinite
                    loop/stack overflow in __muldi3
           Product: compiler-rt
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: compiler-rt
          Assignee: unassignedbugs at nondot.org
          Reporter: troshkovdanil at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

__muldi3(di_int a, di_int b)
{
    dwords x;
    x.all = a;
    dwords y;
    y.all = b;
    dwords r;
    r.all = __muldsi3(x.s.low, y.s.low);
    r.s.high += x.s.high * y.s.low + x.s.low * y.s.high;
    return r.all;
}

Function recursively uses itself (r.s.high += x.s.high * y.s.low + x.s.low *
y.s.high).
It occurs quite legally...
Dumps (-mllvm -print-after-all):

; Function Attrs: nounwind
define i64 @__muldi3(i64 %a, i64 %b) #0 {
entry:
  %x.sroa.0.0.extract.trunc = trunc i64 %a to i32
  %x.sroa.3.0.extract.shift = lshr i64 %a, 32
  %x.sroa.3.0.extract.trunc = trunc i64 %x.sroa.3.0.extract.shift to i32
  %y.sroa.0.0.extract.trunc = trunc i64 %b to i32
  %y.sroa.3.0.extract.shift = lshr i64 %b, 32
  %y.sroa.3.0.extract.trunc = trunc i64 %y.sroa.3.0.extract.shift to i32
  %call = call fastcc i64 @__muldsi3(i32 %x.sroa.0.0.extract.trunc, i32
%y.sroa.0.0.extract.trunc)
  %r.sroa.0.0.extract.trunc = trunc i64 %call to i32
  %r.sroa.2.0.extract.shift = lshr i64 %call, 32
  %r.sroa.2.0.extract.trunc = trunc i64 %r.sroa.2.0.extract.shift to i32
  %mul = mul i32 %x.sroa.3.0.extract.trunc, %y.sroa.0.0.extract.trunc
  %mul12 = mul i32 %x.sroa.0.0.extract.trunc, %y.sroa.3.0.extract.trunc
  %add = add i32 %mul, %mul12
  %add15 = add i32 %r.sroa.2.0.extract.trunc, %add
  %r.sroa.2.0.insert.ext = zext i32 %add15 to i64
  %r.sroa.2.0.insert.shift = shl i64 %r.sroa.2.0.insert.ext, 32
  %r.sroa.0.0.insert.ext = zext i32 %r.sroa.0.0.extract.trunc to i64
  %r.sroa.0.0.insert.mask = and i64 %r.sroa.2.0.insert.shift, -4294967296
  %r.sroa.0.0.insert.insert = or i64 %r.sroa.0.0.insert.mask,
%r.sroa.0.0.insert.ext
  ret i64 %r.sroa.0.0.insert.insert
}
.....
*** IR Dump After Combine redundant instructions ***
; Function Attrs: nounwind
define i64 @__muldi3(i64 %a, i64 %b) #0 {
entry:
  %x.sroa.0.0.extract.trunc = trunc i64 %a to i32
  %x.sroa.3.0.extract.shift = lshr i64 %a, 32
  %y.sroa.0.0.extract.trunc = trunc i64 %b to i32
  %y.sroa.3.0.extract.shift = lshr i64 %b, 32
  %call = call fastcc i64 @__muldsi3(i32 %x.sroa.0.0.extract.trunc, i32
%y.sroa.0.0.extract.trunc)
  %mul = mul i64 %x.sroa.3.0.extract.shift, %b
  %mul12 = mul i64 %y.sroa.3.0.extract.shift, %a
  %add = add i64 %mul, %mul12
  %add1519 = shl i64 %add, 32
  %r.sroa.2.0.extract.shift20 = add i64 %call, %add1519
  ret i64 %r.sroa.2.0.extract.shift20
}

And (mul i64) is __muldi3...

I've looked for similar problems in the Internet and found something like this:

https://groups.google.com/forum/#!topic/llvm-dev/c-i8S5tOSYg

So it looks like the solution is to explicitly use builtins:

     r.all = __muldsi3(x.s.low, y.s.low);
-    r.s.high += x.s.high * y.s.low + x.s.low * y.s.high;
+    r.s.high += __mulsi3(x.s.high, y.s.low) + __mulsi3(x.s.low, y.s.high);
     return r.all;

But we have no __mulsi3...

Any ideas?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141107/360e62ea/attachment.html>


More information about the llvm-bugs mailing list