[llvm-branch-commits] [llvm-branch] r195810 - Merging r195769:

Bill Wendling isanbard at gmail.com
Tue Nov 26 20:52:57 PST 2013


Author: void
Date: Tue Nov 26 22:52:57 2013
New Revision: 195810

URL: http://llvm.org/viewvc/llvm-project?rev=195810&view=rev
Log:
Merging r195769:
------------------------------------------------------------------------
r195769 | dyatkovskiy | 2013-11-26 08:11:03 -0800 (Tue, 26 Nov 2013) | 27 lines

PR17925 bugfix.

Short description.

This issue is about case of treating pointers as integers.
We treat pointers as different if they references different address space.
At the same time, we treat pointers equal to integers (with machine address
width). It was a point of false-positive. Consider next case on 32bit machine:

void foo0(i32 addrespace(1)* %p)
void foo1(i32 addrespace(2)* %p)
void foo2(i32 %p)

foo0 != foo1, while
foo1 == foo2 and foo0 == foo2.

As you can see it breaks transitivity. That means that result depends on order
of how functions are presented in module. Next order causes merging of foo0
and foo1: foo2, foo0, foo1
First foo0 will be merged with foo2, foo0 will be erased. Second foo1 will be
merged with foo2.
Depending on order, things could be merged we don't expect to.

The fix:
Forbid to treat any pointer as integer, except for those, who belong to address space 0.


------------------------------------------------------------------------

Added:
    llvm/branches/release_34/test/Transforms/MergeFunc/ptr-int-transitivity-1.ll
      - copied unchanged from r195769, llvm/trunk/test/Transforms/MergeFunc/ptr-int-transitivity-1.ll
    llvm/branches/release_34/test/Transforms/MergeFunc/ptr-int-transitivity-2.ll
      - copied unchanged from r195769, llvm/trunk/test/Transforms/MergeFunc/ptr-int-transitivity-2.ll
    llvm/branches/release_34/test/Transforms/MergeFunc/ptr-int-transitivity-3.ll
      - copied unchanged from r195769, llvm/trunk/test/Transforms/MergeFunc/ptr-int-transitivity-3.ll
Removed:
    llvm/branches/release_34/test/Transforms/MergeFunc/inttoptr-address-space-2.ll
Modified:
    llvm/branches/release_34/   (props changed)
    llvm/branches/release_34/lib/Transforms/IPO/MergeFunctions.cpp

Propchange: llvm/branches/release_34/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Nov 26 22:52:57 2013
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,195092-195094,195100,195102-195103,195118,195129,195136,195138,195152,195156-195157,195161-195162,195193,195272,195317-195318,195327,195330,195333,195339,195343,195355,195364,195379,195397-195399,195408,195421,195423-195424,195432,195439,195444,195455-195456,195469,195476-195477,195479,195491-195493,195514,195528,195547,195567,195591,195599,195632,195635-195636,195670,195679,195682,195684,195713,195716
+/llvm/trunk:155241,195092-195094,195100,195102-195103,195118,195129,195136,195138,195152,195156-195157,195161-195162,195193,195272,195317-195318,195327,195330,195333,195339,195343,195355,195364,195379,195397-195399,195408,195421,195423-195424,195432,195439,195444,195455-195456,195469,195476-195477,195479,195491-195493,195514,195528,195547,195567,195591,195599,195632,195635-195636,195670,195679,195682,195684,195713,195716,195769

Modified: llvm/branches/release_34/lib/Transforms/IPO/MergeFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_34/lib/Transforms/IPO/MergeFunctions.cpp?rev=195810&r1=195809&r2=195810&view=diff
==============================================================================
--- llvm/branches/release_34/lib/Transforms/IPO/MergeFunctions.cpp (original)
+++ llvm/branches/release_34/lib/Transforms/IPO/MergeFunctions.cpp Tue Nov 26 22:52:57 2013
@@ -210,19 +210,20 @@ private:
 // Any two pointers in the same address space are equivalent, intptr_t and
 // pointers are equivalent. Otherwise, standard type equivalence rules apply.
 bool FunctionComparator::isEquivalentType(Type *Ty1, Type *Ty2) const {
+
+  PointerType *PTy1 = dyn_cast<PointerType>(Ty1);
+  PointerType *PTy2 = dyn_cast<PointerType>(Ty2);
+
+  if (TD) {
+    if (PTy1 && PTy1->getAddressSpace() == 0) Ty1 = TD->getIntPtrType(Ty1);
+    if (PTy2 && PTy2->getAddressSpace() == 0) Ty2 = TD->getIntPtrType(Ty2);
+  }
+
   if (Ty1 == Ty2)
     return true;
-  if (Ty1->getTypeID() != Ty2->getTypeID()) {
-    if (TD) {
-
-      if (isa<PointerType>(Ty1) && Ty2 == TD->getIntPtrType(Ty1))
-        return true;
 
-      if (isa<PointerType>(Ty2) && Ty1 == TD->getIntPtrType(Ty2))
-        return true;
-    }
+  if (Ty1->getTypeID() != Ty2->getTypeID())
     return false;
-  }
 
   switch (Ty1->getTypeID()) {
   default:
@@ -244,8 +245,7 @@ bool FunctionComparator::isEquivalentTyp
     return true;
 
   case Type::PointerTyID: {
-    PointerType *PTy1 = cast<PointerType>(Ty1);
-    PointerType *PTy2 = cast<PointerType>(Ty2);
+    assert(PTy1 && PTy2 && "Both types must be pointers here.");
     return PTy1->getAddressSpace() == PTy2->getAddressSpace();
   }
 

Removed: llvm/branches/release_34/test/Transforms/MergeFunc/inttoptr-address-space-2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_34/test/Transforms/MergeFunc/inttoptr-address-space-2.ll?rev=195809&view=auto
==============================================================================
--- llvm/branches/release_34/test/Transforms/MergeFunc/inttoptr-address-space-2.ll (original)
+++ llvm/branches/release_34/test/Transforms/MergeFunc/inttoptr-address-space-2.ll (removed)
@@ -1,29 +0,0 @@
-; RUN: opt -mergefunc -S < %s | FileCheck %s
-target datalayout = "e-p:32:32:32-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-n8:16:32-S128"
-
-%.qux.2496 = type { i16, %.qux.2497 }
-%.qux.2497 = type { i8, i16 }
-%.qux.2585 = type { i16, i16, i8 addrspace(1)* }
-
- at g2 = external addrspace(1) constant [9 x i8], align 1
- at g3 = internal hidden addrspace(1) constant [1 x i8*] [i8* bitcast (i8 addrspace(1)* (%.qux.2585 addrspace(1)*)* @func35 to i8*)]
-
-
-define internal hidden i16 @func10(%.qux.2496 addrspace(1)* nocapture %this) align 2 {
-bb:
-  %tmp = getelementptr inbounds %.qux.2496 addrspace(1)* %this, i32 0, i32 1, i32 1
-  %tmp1 = load i16 addrspace(1)* %tmp, align 4
-  ret i16 %tmp1
-}
-
-; Checks that this can be merged with an address space differently sized than 0
-define internal hidden i8 addrspace(1)* @func35(%.qux.2585 addrspace(1)* nocapture %this) align 2 {
-bb:
-; CHECK-LABEL: @func35(
-; CHECK: %[[V2:.+]] = bitcast %.qux.2585 addrspace(1)* %{{.*}} to %.qux.2496 addrspace(1)*
-; CHECK: %[[V3:.+]] = tail call i16 @func10(%.qux.2496 addrspace(1)* %[[V2]])
-; CHECK: %{{.*}} = inttoptr i16 %[[V3]] to i8 addrspace(1)*
-  %tmp = getelementptr inbounds %.qux.2585 addrspace(1)* %this, i32 0, i32 2
-  %tmp1 = load i8 addrspace(1)* addrspace(1)* %tmp, align 4
-  ret i8 addrspace(1)* %tmp1
-}





More information about the llvm-branch-commits mailing list