[PATCH] D101970: [X86FixupLEAs] Transform the sequence LEA/SUB to SUB/SUB

Guozhi Wei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 24 13:23:10 PDT 2021


Carrot updated this revision to Diff 347480.
Carrot added a comment.

Thanks for the report!

The problem is in

  -       lea    (%rax,%rcx,1),%ebp
          mov    %esi,%edi
  -       sub    %ebp,%edi
  -       jbe    <_ZNK5clang7tooling12Replacements5mergeERKS1_+0x279>
  +       sub    %eax,%edi
  +       sub    %ecx,%edi
  +       jbe    <_ZNK5clang7tooling12Replacements5mergeERKS1_+0x278>

Previously I thought X - (Y + Z) generates same flags as X - Y - Z, unfortunately it is not true when X - Y overflows.
In one execution of the code snippet, I got
rsi            0x3                 3
rax            0x5                 5
rcx            0x0                 0
Before the transformation the last sub generates CF=1.
After the transformation the last sub generates CF=0.
So it causes wrong behavior for the following branch.

This patch should fix the problem.

@RKSimon, could you please take another look.

@davezarzycki, could you help to test this patch with your configuration?

thanks!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101970/new/

https://reviews.llvm.org/D101970

Files:
  llvm/include/llvm/CodeGen/TargetInstrInfo.h
  llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
  llvm/lib/Target/X86/X86FixupLEAs.cpp
  llvm/lib/Target/X86/X86InstrInfo.cpp
  llvm/lib/Target/X86/X86InstrInfo.h
  llvm/test/CodeGen/X86/2009-03-23-MultiUseSched.ll
  llvm/test/CodeGen/X86/lea-opt2.ll
  llvm/test/CodeGen/X86/vp2intersect_multiple_pairs.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101970.347480.patch
Type: text/x-patch
Size: 25273 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210524/004ca9e1/attachment.bin>


More information about the llvm-commits mailing list