https://bugs.llvm.org/show_bug.cgi?id=39092

            Bug ID: 39092
           Summary: Inefficient lowering of constant, negative, anyext
                    return values
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedb...@nondot.org
          Reporter: a...@lowrisc.org
                CC: llvm-bugs@lists.llvm.org

Consider a function returning a constant negative value, e.g.

define i16 @neg_const() nounwind {
  ret i16 -2047
}

Compile this on a target for which i16 is not a legal type, e.g. PowerPC. For
llc -mtriple=powerpc, the following assembly is generated:
        lis 3, 0
        ori 3, 3, 65436
        blr


We'd rather see:
        li 3, -100
        blr

The issue is that SelectionDAGBuilder::visitRet will call
SelectionDAG::getCopyToParts with ExtendKind = ISD::ANY_EXTEND. This calls
SelectionDAG::getNode with ISD::ANY_EXTEND, which will recognise it has a
constant argument and choose to zero-extend it. This generates the i32 constant
65436 (i.e. zext of int16(-100)) rather than the preferable -100.

By the time target instruction selection code is reached, there is no way to
know that a sign-extended form of the original constant could have been used.

As a quick experiment I changed the constant-folding code in
SelectionDAG::getNode so it performs a sign-extend for ANY_EXTEND input. That
fixes this particular issue as expected but leads to incorrect codegen
elsewhere, though I haven't yet had a chance to explore in more detail.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to