diff options
author | Craig Topper <craig.topper@intel.com> | 2018-08-22 18:24:13 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@intel.com> | 2018-08-22 18:24:13 +0000 |
commit | 87f78cfe15055f5ddc1756b65bb5ef6e0013153a (patch) | |
tree | 2320d89a21be021a26c550d9188b7c0d5c14a5ee /llvm/lib/Target/X86/X86OptimizeLEAs.cpp | |
parent | ff363539c637c3078e3b6be886184ce327d2773a (diff) | |
download | bcm5719-llvm-87f78cfe15055f5ddc1756b65bb5ef6e0013153a.tar.gz bcm5719-llvm-87f78cfe15055f5ddc1756b65bb5ef6e0013153a.zip |
[X86] In OptimizeLEAs pass, check that the key is in the LEAs map before accessing
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
Patch by Tom Rix.
Differential Revision: https://reviews.llvm.org/D50780
llvm-svn: 340434
Diffstat (limited to 'llvm/lib/Target/X86/X86OptimizeLEAs.cpp')
-rw-r--r-- | llvm/lib/Target/X86/X86OptimizeLEAs.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/Target/X86/X86OptimizeLEAs.cpp b/llvm/lib/Target/X86/X86OptimizeLEAs.cpp index 42db51b3cf0..b56d02b6bfb 100644 --- a/llvm/lib/Target/X86/X86OptimizeLEAs.cpp +++ b/llvm/lib/Target/X86/X86OptimizeLEAs.cpp @@ -510,12 +510,16 @@ bool OptimizeLEAPass::removeRedundantAddrCalc(MemOpMap &LEAs) { MemOpNo += X86II::getOperandBias(Desc); + // Do not call chooseBestLEA if there was no matching LEA + auto Insns = LEAs.find(getMemOpKey(MI, MemOpNo)); + if (Insns == LEAs.end()) + continue; + // Get the best LEA instruction to replace address calculation. MachineInstr *DefMI; int64_t AddrDispShift; int Dist; - if (!chooseBestLEA(LEAs[getMemOpKey(MI, MemOpNo)], MI, DefMI, AddrDispShift, - Dist)) + if (!chooseBestLEA(Insns->second, MI, DefMI, AddrDispShift, Dist)) continue; // If LEA occurs before current instruction, we can freely replace |