[llvm] ad9dad9 - [BasicAA] Bail out earlier for invalid shift amount

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 27 04:42:09 PDT 2021


Author: Nikita Popov
Date: 2021-03-27T12:41:16+01:00
New Revision: ad9dad93ff1237aed820bac8ec8e172e73af786d

URL: https://github.com/llvm/llvm-project/commit/ad9dad93ff1237aed820bac8ec8e172e73af786d
DIFF: https://github.com/llvm/llvm-project/commit/ad9dad93ff1237aed820bac8ec8e172e73af786d.diff

LOG: [BasicAA] Bail out earlier for invalid shift amount

Currently, we'd produce an incorrect decomposition, because we
already recursively called GetLinearExpression(), so the Scale=1,
Offset=0 will not necessarily be relative to the shl itself.

Now, this doesn't actually matter for functional correctness,
because such a shift is poison anyway, so its okay to return
an incorrect decomposition. It's still unnecessarily confusing
though, and we can easily avoid this by checking the bitwidth
earlier.

Added: 
    

Modified: 
    llvm/lib/Analysis/BasicAliasAnalysis.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 6246cad66776..ab0d180a99e1 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -297,9 +297,6 @@ static bool isObjectSize(const Value *V, uint64_t Size, const DataLayout &DL,
         Scale *= RHS;
         break;
       case Instruction::Shl:
-        V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, ZExtBits,
-                                SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
-
         // We're trying to linearize an expression of the kind:
         //   shl i8 -128, 36
         // where the shift count exceeds the bitwidth of the type.
@@ -312,6 +309,8 @@ static bool isObjectSize(const Value *V, uint64_t Size, const DataLayout &DL,
           return V;
         }
 
+        V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, ZExtBits,
+                                SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
         Offset <<= RHS.getLimitedValue();
         Scale <<= RHS.getLimitedValue();
         break;


        


More information about the llvm-commits mailing list