[all-commits] [llvm/llvm-project] d1fc8f: [X86] Prevent infinite loop in SelectionDAG when l...

Maurice Heumann via All-commits all-commits at lists.llvm.org
Thu Jul 13 04:21:07 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d1fc8f7211b12fd044a5f46d452fc505144a4f82
      https://github.com/llvm/llvm-project/commit/d1fc8f7211b12fd044a5f46d452fc505144a4f82
  Author: Maurice Heumann <maurice.heumann at wibu.com>
  Date:   2023-07-13 (Thu, 13 Jul 2023)

  Changed paths:
    M llvm/lib/Target/X86/X86ISelLowering.cpp
    A llvm/test/CodeGen/X86/select-neg.ll

  Log Message:
  -----------
  [X86] Prevent infinite loop in SelectionDAG when lowering negations

In certain cases, lowering negations can cause an infinite loop in SelectionDAG on X86.

The following snippet shows that behaviour:
https://godbolt.org/z/5hP45T4hY

What happens is that ADD(XOR(..., -1), 1) is detected as the two's complement and transformed into SUB(0, ...)
However, immediates can not be encoded as the LHS of a SUB on X86.
Therefore it is transformed back into an ADD/XOR pair, which is then again transformed into a SUB and so on.

In that specific case, I still think it is valid to display this as a SUB(0,...) , because it should eventually be lowered as a NEG.
Which seems better than an ADD/XOR pair.

Adding an exception to the X86 specific handling for SUBs with 0 LHS operand fixes this infinite loop.

Differential Revision: https://reviews.llvm.org/D154575




More information about the All-commits mailing list