[PATCH] D116238: [mips] Add -mfix4300 flag to enable vr4300 mulmul bugfix pass

Random via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 23 13:48:32 PST 2021


Random06457 created this revision.
Random06457 added a reviewer: atanasyan.
Herald added subscribers: dang, jrtc27, hiraditya, arichardson, mgorny, sdardis.
Random06457 requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Early revisions of the VR4300 have a hardware bug where two consecutive multiplications can produce an incorrect result in the second multiply.
This revision adds the `-mfix4300` flag to llvm (and clang) which, when passed, provides a software fix for this issue.

**More precise description of the "mulmul" bug:**

  1: mul.[s,d] fd,fs,ft
  2: mul.[s,d] fd,fs,ft  or  [D]MULT[U] rs,rt

When the above sequence is executed by the CPU, if at least one of the source operands of the first mul instruction happens to be `sNaN`, `0` or `Infinity`, then the second mul instruction may produce an incorrect result.
This can happen both if the two mul instructions are next to each other of if the first one is in a delay slot and the second is the first instruction of the branch target.

**Description of the fix:**
This fix adds a backend pass to llvm which scans for mul instructions in each basic block and happens a nop whenever the following conditions are met:

- The current instruction is a single or double-precision floating-point mul instruction.
- The next instrution is either a mul instruction (any kind) or a branch instruction.

**Note:**
I chose `-mfix4300` as a name for the flag to follow the GCC nomenclature but I don't know if this is a good name.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116238

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  llvm/lib/Target/Mips/CMakeLists.txt
  llvm/lib/Target/Mips/Mips.h
  llvm/lib/Target/Mips/MipsMulMulBugPass.cpp
  llvm/lib/Target/Mips/MipsTargetMachine.cpp
  llvm/test/CodeGen/Mips/vr4300mulmul/mulbranch.ll
  llvm/test/CodeGen/Mips/vr4300mulmul/mulmul.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116238.396079.patch
Type: text/x-patch
Size: 7576 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211223/ba1b6a75/attachment.bin>


More information about the cfe-commits mailing list