OSDN Git Service

[MachineOutliner] Fix offset overflow check
authorJessica Paquette <jpaquette@apple.com>
Thu, 7 Dec 2017 21:51:43 +0000 (21:51 +0000)
committerJessica Paquette <jpaquette@apple.com>
Thu, 7 Dec 2017 21:51:43 +0000 (21:51 +0000)
The offset overflow check before was incorrect. It would always give the
correct result, but it was comparing the SCALED potential fixed-up offset
against an UNSCALED minimum/maximum. As a result, the outliner was missing a
bunch of frame setup/destroy instructions that ought to have been safe to
outline. This fixes that, and adds an instruction to the .mir test that
failed the old test.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320090 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/AArch64/AArch64InstrInfo.cpp
test/CodeGen/AArch64/machine-outliner.mir

index b88beda..9e12b1a 100644 (file)
@@ -4833,15 +4833,17 @@ AArch64InstrInfo::getOutliningType(MachineInstr &MI) const {
 
       // Find the minimum/maximum offset for this instruction and check if
       // fixing it up would be in range.
-      int64_t MinOffset, MaxOffset;
-      unsigned DummyScale;
-      getMemOpInfo(MI.getOpcode(), DummyScale, DummyWidth, MinOffset,
+      int64_t MinOffset, MaxOffset; // Unscaled offsets for the instruction.
+      unsigned Scale; // The scale to multiply the offsets by.
+      getMemOpInfo(MI.getOpcode(), Scale, DummyWidth, MinOffset,
                    MaxOffset);
 
       // TODO: We should really test what happens if an instruction overflows.
       // This is tricky to test with IR tests, but when the outliner is moved
       // to a MIR test, it really ought to be checked.
-      if (Offset + 16 < MinOffset || Offset + 16 > MaxOffset)
+
+      Offset += 16; // Update the offset to what it would be if we outlined.
+      if (Offset < MinOffset * Scale || Offset > MaxOffset * Scale)
         return MachineOutlinerInstrType::Illegal;
 
       // It's in range, so we can outline it.
index 3ff2d2a..ee3daf1 100644 (file)
@@ -39,6 +39,7 @@ body:             |
     %w30 = ORRWri %wzr, 1
     %lr = ORRXri %xzr, 1
 
+    %x20, %x19 = LDPXi %sp, 10
     %w16 = ORRWri %wzr, 1
     %w16 = ORRWri %wzr, 1
     %w16 = ORRWri %wzr, 1
@@ -50,6 +51,7 @@ body:             |
 
     %w3 = ORRWri %wzr, 1993
 
+    %x20, %x19 = LDPXi %sp, 10
     %w16 = ORRWri %wzr, 1
     %w16 = ORRWri %wzr, 1
     %w16 = ORRWri %wzr, 1
@@ -61,6 +63,7 @@ body:             |
 
     %w4 = ORRWri %wzr, 1994
 
+    %x20, %x19 = LDPXi %sp, 10
     %w16 = ORRWri %wzr, 1
     %w16 = ORRWri %wzr, 1
     %w16 = ORRWri %wzr, 1