[llvm-bugs] [Bug 35203] New: ARMConstantIslands incorrectly removes t2LEA when optimizing a Thumb-2 jump table

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Nov 4 02:07:17 PDT 2017


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

            Bug ID: 35203
           Summary: ARMConstantIslands incorrectly removes t2LEA when
                    optimizing a Thumb-2 jump table
           Product: libraries
           Version: 4.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: ARM
          Assignee: unassignedbugs at nondot.org
          Reporter: editing at zju.edu.cn
                CC: llvm-bugs at lists.llvm.org

Created attachment 19370
  --> https://bugs.llvm.org/attachment.cgi?id=19370&action=edit
MIR files before and after ARMConstantIslands is run

Overview:
When optimizing a Thumb-2 jump table, ARMConstantIslands::preserveBaseRegister
attempts to determine whether the t2LEA instruction that loads a register with
the base address of the jump table will still be in use after the jump table is
optimized. However, the preserveBaseRegister method fails to handle a corner
case, causing the t2LEA instruction to be incorrectly removed, as shown in the
following example:

; Basic block containing t2BR_JT before ARMConstantIslands is run:

%r1 = t2LEApcrelJT %jump-table.0, 14, _
%r2 = t2ADDrs killed %r1, %r0, 18, 14, _, _
tSTRi %r2, killed %r3, 0, 14, _, debug-location !29 :: (store 4 into %ir.1)
t2BR_JT killed %r2, killed %r0, %jump-table.0

; The same basic block after ARMConstantIslands is run:

%r2 = t2ADDrs killed %r1, %r0, 18, 14, _, _
tSTRi %r2, killed %r3, 0, 14, _, debug-location !29 :: (store 4 into %ir.1)
t2TBB_JT %pc, killed %r0, %jump-table.0, 0

In the example above, the t2LEApcrelJT is incorrectly removed, although the
register it defines (%r1) is used by the t2ADDrs instruction. Note that the
register the t2ADDrs instruction defines (%r2) is in turn used by the tSTRi
instruction.

Step to reproduce:
Run llc on the file f.mir in the attached archive with the following command
line:

llc -mtriple=thumbv7m-none-none-eabi -mcpu=cortex-m3 -float-abi=soft
-run-pass=arm-cp-islands -o f-after-arm-cp-islands.mir f.mir

The output file should be identical to the f-after-arm-cp-islands.mir file in
the attached archive.

Actual Results:
The t2LEApcrelJT instruction is incorrectly removed, as shown above.

Expected Results:
The t2LEApcrelJT instruction should not be removed.

Additional information:
In the test case above, the output of the t2LEApcrelJT instruction is only used
by the t2ADDrs instruction, which calculates the address of the jump table
entry. Even if the jump table could be optimized to use a tbb/tbh instruction,
the t2ADDrs cannot be removed because it is used by the tSTRi instruction.
Therefore, the t2LEApcrelJT instruction cannot be remove either. In a word,
when the t2ADDrs cannot be safely removed, preserveBaseRegister should ensure
that the t2LEApcrelJT is not removed either, because the t2ADDrs instructions
uses its output.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171104/29b8a3f6/attachment.html>


More information about the llvm-bugs mailing list