Add a 2 byte safety margin in offset computations.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Sat, 31 Mar 2012 00:06:44 +0000 (00:06 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Sat, 31 Mar 2012 00:06:44 +0000 (00:06 +0000)
ARMConstantIslandPass still has bugs where jump table compression can
cause constant pool entries to go out of range.

Add a safety margin of 2 bytes when placing constant islands, but use
the real max displacement for verification.

<rdar://problem/11156595>

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

lib/Target/ARM/ARMConstantIslandPass.cpp

index f5221f05e42f61800aed0bbbd7ebb3bd198cc6c6..fc35c7cb02005e23dded23bb9fa117a76fcd9a02 100644 (file)
@@ -209,8 +209,9 @@ namespace {
       }
       /// getMaxDisp - Returns the maximum displacement supported by MI.
       /// Correct for unknown alignment.
+      /// Conservatively subtract 2 bytes to handle weird alignment effects.
       unsigned getMaxDisp() const {
-        return KnownAlignment ? MaxDisp : MaxDisp - 2;
+        return (KnownAlignment ? MaxDisp : MaxDisp - 2) - 2;
       }
     };
 
@@ -350,7 +351,9 @@ void ARMConstantIslands::verify() {
   for (unsigned i = 0, e = CPUsers.size(); i != e; ++i) {
     CPUser &U = CPUsers[i];
     unsigned UserOffset = getUserOffset(U);
-    if (isCPEntryInRange(U.MI, UserOffset, U.CPEMI, U.getMaxDisp(), U.NegOk,
+    // Verify offset using the real max displacement without the safety
+    // adjustment.
+    if (isCPEntryInRange(U.MI, UserOffset, U.CPEMI, U.getMaxDisp()+2, U.NegOk,
                          /* DoDump = */ true)) {
       DEBUG(dbgs() << "OK\n");
       continue;