[llvm] r321873 - [BasicAA] Fix linearization of shifts beyond the bitwidth.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 5 08:18:47 PST 2018


Author: davide
Date: Fri Jan  5 08:18:47 2018
New Revision: 321873

URL: http://llvm.org/viewvc/llvm-project?rev=321873&view=rev
Log:
[BasicAA] Fix linearization of shifts beyond the bitwidth.

Thanks to Simon Pilgrim for the reduced testcase.
Fixes PR35821.

Added:
    llvm/trunk/test/Analysis/BasicAA/pr35821.ll
Modified:
    llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp

Modified: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp?rev=321873&r1=321872&r2=321873&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp Fri Jan  5 08:18:47 2018
@@ -285,6 +285,19 @@ static bool isObjectSize(const Value *V,
       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.
+        // We can't decompose this further (the expression would return
+        // a poison value).
+        if (Offset.getBitWidth() < RHS.getLimitedValue() ||
+            Scale.getBitWidth() < RHS.getLimitedValue()) {
+          Scale = 1;
+          Offset = 0;
+          return V;
+        }
+
         Offset <<= RHS.getLimitedValue();
         Scale <<= RHS.getLimitedValue();
         // the semantics of nsw and nuw for left shifts don't match those of

Added: llvm/trunk/test/Analysis/BasicAA/pr35821.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BasicAA/pr35821.ll?rev=321873&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/BasicAA/pr35821.ll (added)
+++ llvm/trunk/test/Analysis/BasicAA/pr35821.ll Fri Jan  5 08:18:47 2018
@@ -0,0 +1,11 @@
+; RUN: opt %s -aa-eval -disable-output 2>&1 | FileCheck %s
+
+; CHECK: 6 Total Alias Queries Performed
+; CHECK-NEXT: 6 no alias responses
+
+define void @patatino() {
+  %G26 = getelementptr i1, i1* undef, i1 undef
+  %B20 = shl i8 -128, 16
+  %G47 = getelementptr i1*, i1** undef, i8 %B20
+  ret void
+}




More information about the llvm-commits mailing list