[all-commits] [llvm/llvm-project] 670c92: [CodeGen] Remove redundent instructions generated ...

Peter Rong via All-commits all-commits at lists.llvm.org
Thu Mar 30 00:36:10 PDT 2023

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 670c92a415d0c646dc9f6b08a0f0c817d17ebb46
  Author: Peter Rong <PeterRong96 at gmail.com>
  Date:   2023-03-30 (Thu, 30 Mar 2023)

  Changed paths:
    M llvm/lib/CodeGen/CodeGenPrepare.cpp
    A llvm/test/CodeGen/X86/pr58538.ll

  Log Message:
  [CodeGen] Remove redundent instructions generated by combineAddrModes.

CodeGenPare may optimize memory access modes.
During such optimization, it might create a new instruction representing combined value.
Later, If the optimization failed, the generated value is not removed and remains a dead instruction.

Normally this won't be a problem as dead code will be eliminated later.
However, in this case (Issue 58538), the generated instruction may trigger an infinite loop.
The infinite loop involves `sinkCmpExpression`, where it tries to optimize the placeholder generated by us.
(See the test case detailed in the issue)

To fix this, we remove the unnecessary placeholder immediately when we abort the optimization.
`AddressingModeCombiner` will keep track of the placeholder, and remove it if it is an inserted placeholder and has no uses.
This patch fixes https://github.com/llvm/llvm-project/issues/58538, a test is also included.

Reviewed By: skatkov

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

More information about the All-commits mailing list