[PATCH] D50780: Check that the key is in the LEAs map before accessing

Tom Rix via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 15 07:09:26 PDT 2018


trixirt created this revision.
trixirt added reviewers: aturetsk, qcolombet, samsonov.
Herald added a subscriber: llvm-commits.

When the key is not already in the map, the access operator[] creates an empty value and grows the map.
Resizing a map is very slow, so this needs to be avoided.

Found with csmith + asserts.

May help with 
https://bugs.llvm.org/show_bug.cgi?id=25843


Repository:
  rL LLVM

https://reviews.llvm.org/D50780

Files:
  lib/Target/X86/X86OptimizeLEAs.cpp


Index: lib/Target/X86/X86OptimizeLEAs.cpp
===================================================================
--- lib/Target/X86/X86OptimizeLEAs.cpp
+++ lib/Target/X86/X86OptimizeLEAs.cpp
@@ -514,8 +514,12 @@
     MachineInstr *DefMI;
     int64_t AddrDispShift;
     int Dist;
-    if (!chooseBestLEA(LEAs[getMemOpKey(MI, MemOpNo)], MI, DefMI, AddrDispShift,
-                       Dist))
+    MemOpKey key = getMemOpKey(MI, MemOpNo);
+
+    if (!LEAs.count(key))
+      continue;
+
+    if (!chooseBestLEA(LEAs[key], MI, DefMI, AddrDispShift, Dist))
       continue;
 
     // If LEA occurs before current instruction, we can freely replace


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50780.160794.patch
Type: text/x-patch
Size: 644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180815/7ce1cd39/attachment.bin>


More information about the llvm-commits mailing list