This is an archive of the discontinued LLVM Phabricator instance.

[ConstantFolding] Add constant folding for smul.fix and smul.fix.sat
ClosedPublic

Authored by bjope on Jun 16 2019, 8:23 AM.

Details

Summary

This patch teaches ConstantFolding to constant fold
both scalar and vector variants of llvm.smul.fix and
llvm.smul.fix.sat.

As described in the LangRef rounding is unspecified for
these instrinsics. If the result cannot be represented
exactly the default behavior in ConstantFolding is to
round down towards negative infinity. If a target has a
preferred rounding that is different some kind of target
hook would be needed (same strategy as used by the
SelectionDAG legalizer).

Diff Detail

Repository
rL LLVM

Event Timeline

bjope created this revision.Jun 16 2019, 8:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2019, 8:23 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
leonardchan accepted this revision.Jun 18 2019, 2:55 PM
This revision is now accepted and ready to land.Jun 18 2019, 2:55 PM
This revision was automatically updated to reflect the committed changes.
nikic added inline comments.Jun 19 2019, 9:43 AM
llvm/trunk/lib/Analysis/ConstantFolding.cpp
2205

As a possible follow-up cleanup, this can be merged into the fshl/fshr code below. The smul_fix case could bail out if C0, C1 or C2 are null (or handle them, if there is interest to support undef operands).