[PATCH] D111857: 【TwoAddressInstructionPass】 Put all new instructions into DistanceMap

Guozhi Wei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 20 14:33:41 PDT 2021


Carrot added inline comments.


================
Comment at: llvm/test/CodeGen/X86/distancemap.mir:71
+    ; CHECK-NEXT: [[COPY6:%[0-9]+]]:gr16 = COPY [[COPY3]]
+    ; CHECK-NEXT: [[ADD16rr:%[0-9]+]]:gr16 = ADD16rr [[ADD16rr]], killed [[COPY4]], implicit-def $eflags
+    ; CHECK-NEXT: undef %11.sub_16bit:gr32 = COPY killed [[ADD16rr]]
----------------
pengfei wrote:
> This does seem correct to me. The input in line 88 is
> `%10:gr16 = ADD16rr killed %3:gr16($di), killed %5:gr16, ...`
> But the output turns into add `[[COPY4]]($esi)`?
The operands are commuted. This is the exact difference caused by this patch.

Function isProfitableToCommute calls noUseAfterLastDef with argument [[COPY3]] when processing this ADD instruction, DistanceMap is used in noUseAfterLastDef to decide MI's position.  When the LEA instruction was generated, several COPY and IMPLICIT_DEF instructions are generated. If they are not added to DistanceMap, noUseAfterLastDef misses the use of [[COPY3]] and returns wrong value. With this patch noUseAfterLastDef can correctly find the use of [[COPY3]] and returns correct value, causes isProfitableToCommute to return different commute decision.


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

https://reviews.llvm.org/D111857



More information about the llvm-commits mailing list