[PATCH] D38499: [BasicAA] Fix adjustToPointerSize in BasicAliasAnalysis.cpp for ptr > 64b

Michael Ferguson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 3 06:12:06 PDT 2017


mppf created this revision.

The function adjustToPointerSize in BasicAliasAnalysis.cpp includes
an assertion that the pointer size is <= 64 bits. I'm working on some
uses of LLVM that need 128-bit pointers. This change simply adjusts
this function to allow 128-bit pointers and to not worry about adjusting
offsets to handle integer sizes < int64_t in that case.

The logic being adjusted has existed in some form in LLVM since
at least r111433 in 2010. LLVM has become much better at handling
varied pointer sizes since then.

Includes a test case that fails without this change.


https://reviews.llvm.org/D38499

Files:
  lib/Analysis/BasicAliasAnalysis.cpp
  test/Analysis/BasicAA/128-bit-ptr.ll


Index: test/Analysis/BasicAA/128-bit-ptr.ll
===================================================================
--- /dev/null
+++ test/Analysis/BasicAA/128-bit-ptr.ll
@@ -0,0 +1,19 @@
+; RUN: opt -S -basicaa -gvn < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128-p100:128:64:64-p101:128:64:64"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i64 @test1(double addrspace(100)* addrspace(100)* %a) {
+  %p = load double addrspace(100)*, double addrspace(100)* addrspace(100)* %a
+  %e21 = getelementptr inbounds double, double addrspace(100)* %p, i128 1
+  %e2 = getelementptr inbounds double, double addrspace(100)* %e21, i128 1
+  %c2 = bitcast double addrspace(100)* %e2 to i64 addrspace(100)*
+  %d = load i64, i64 addrspace(100)* %c2
+  %sum = add i64 0, %d
+  ret i64 %sum
+; This test checks against an assertion in opt so is light on
+; checking the generated code.
+;
+; CHECK-LABEL: @test1(
+; CHECK: ret i64
+}
Index: lib/Analysis/BasicAliasAnalysis.cpp
===================================================================
--- lib/Analysis/BasicAliasAnalysis.cpp
+++ lib/Analysis/BasicAliasAnalysis.cpp
@@ -363,9 +363,12 @@
 /// particular for 32b programs with negative indices that rely on two's
 /// complement wrap-arounds for precise alias information.
 static int64_t adjustToPointerSize(int64_t Offset, unsigned PointerSize) {
-  assert(PointerSize <= 64 && "Invalid PointerSize!");
-  unsigned ShiftBits = 64 - PointerSize;
-  return (int64_t)((uint64_t)Offset << ShiftBits) >> ShiftBits;
+  if (PointerSize < 64) {
+    unsigned ShiftBits = 64 - PointerSize;
+    return (int64_t)((uint64_t)Offset << ShiftBits) >> ShiftBits;
+  } else {
+    return Offset;
+  }
 }
 
 /// If V is a symbolic pointer expression, decompose it into a base pointer


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38499.117514.patch
Type: text/x-patch
Size: 1908 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171003/ef285a7b/attachment.bin>


More information about the llvm-commits mailing list