[LLVMbugs] [Bug 1874] New: Multiplication codegen issues

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Tue Dec 18 23:55:18 PST 2007


           Summary: Multiplication codegen issues
           Product: libraries
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: Common Code Generator Code
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: evan.cheng at apple.com
                CC: llvmbugs at cs.uiuc.edu

Chris noticed this:

We're missing an obvious fold of a load into imul:

int test(long a, long b) { return a * b; }

LLVM produces:
        movl    4(%esp), %ecx
        movl    8(%esp), %eax
        imull   %ecx, %eax

        movl    8(%esp), %eax
        imull   4(%esp), %eax

I've looked into this and noticed a bigger issue with multiplication codegen in

On x86, ISD::MUL i32 is marked expand. Legalizer expands this to a
ISD::SMUL_LOHI. DAG combiner failed to turn it back into a ISD::MUL (it's high
part isn't needed) because ISD::MUL is not legal. X86 isel then sees it's a
ISD::SMUL_LOHI whose high value is not needed and create a new ISD::MUL node
and select it to an IMULL node. However since the operands (which are loads)
have multiple uses, they are not folded into the IMULL node.

1. ISD::MUL i32 should not have been marked expand. It's a perfectly selectable
node. Only i64 ISD::MUL (unless it's x86-64) should be marked expand.
2. It makes sense for the legalizer to issue {S|U}MUL_LOHI when expanding a
MUL. But we also need DAG combiner to combine MULH{S|U} + MUL to a
3. X86 isel should not need any hack to handle {S|U}MUL_LOHI nodes whose high
value is not used.

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