[llvm-commits] [llvm] r124368 - in /llvm/trunk: lib/Transforms/IPO/MergeFunctions.cpp test/Transforms/MergeFunc/vector.ll
Nick Lewycky
nicholas at mxc.ca
Thu Jan 27 00:38:19 PST 2011
Author: nicholas
Date: Thu Jan 27 02:38:19 2011
New Revision: 124368
URL: http://llvm.org/viewvc/llvm-project?rev=124368&view=rev
Log:
Fix surprising missed optimization in mergefunc where we forgot to consider
that relationships like "i8* null" is equivalent to "i32* null".
Added:
llvm/trunk/test/Transforms/MergeFunc/vector.ll
Modified:
llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
Modified: llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp?rev=124368&r1=124367&r2=124368&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp Thu Jan 27 02:38:19 2011
@@ -460,9 +460,18 @@
if (V1 == F2 && V2 == F1)
return true;
- // TODO: constant expressions with GEP or references to F1 or F2.
- if (isa<Constant>(V1))
- return V1 == V2;
+ if (isa<Constant>(V1)) {
+ if (V1 == V2) return true;
+ const Constant *C1 = cast<Constant>(V1);
+ const Constant *C2 = dyn_cast<Constant>(V2);
+ if (!C2) return false;
+ // TODO: constant expressions with GEP or references to F1 or F2.
+ if (C1->isNullValue() && C2->isNullValue() &&
+ isEquivalentType(C1->getType(), C2->getType()))
+ return true;
+ return C1->getType()->canLosslesslyBitCastTo(C2->getType()) &&
+ C1 == ConstantExpr::getBitCast(const_cast<Constant*>(C2), C1->getType());
+ }
if (isa<InlineAsm>(V1) && isa<InlineAsm>(V2)) {
const InlineAsm *IA1 = cast<InlineAsm>(V1);
Added: llvm/trunk/test/Transforms/MergeFunc/vector.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/MergeFunc/vector.ll?rev=124368&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/MergeFunc/vector.ll (added)
+++ llvm/trunk/test/Transforms/MergeFunc/vector.ll Thu Jan 27 02:38:19 2011
@@ -0,0 +1,76 @@
+; RUN: opt -mergefunc -stats -disable-output < %s |& grep {functions merged}
+
+; This test is checks whether we can merge
+; vector<intptr_t>::push_back(0)
+; and
+; vector<void *>::push_back(0)
+; .
+
+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"
+target triple = "x86_64-unknown-linux-gnu"
+
+%0 = type { i32, void ()* }
+%1 = type { i64, i1 }
+%"class.std::vector" = type { [24 x i8] }
+
+ at vi = global %"class.std::vector" zeroinitializer, align 8
+ at __dso_handle = external unnamed_addr global i8*
+ at vp = global %"class.std::vector" zeroinitializer, align 8
+ at llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @_GLOBAL__I_a }]
+
+define linkonce_odr void @_ZNSt6vectorIlSaIlEED1Ev(%"class.std::vector"* nocapture %this) unnamed_addr align 2 {
+entry:
+ %tmp2.i.i = bitcast %"class.std::vector"* %this to i64**
+ %tmp3.i.i = load i64** %tmp2.i.i, align 8, !tbaa !0
+ %tobool.i.i.i = icmp eq i64* %tmp3.i.i, null
+ br i1 %tobool.i.i.i, label %_ZNSt6vectorIlSaIlEED2Ev.exit, label %if.then.i.i.i
+
+if.then.i.i.i: ; preds = %entry
+ %0 = bitcast i64* %tmp3.i.i to i8*
+ tail call void @_ZdlPv(i8* %0) nounwind
+ ret void
+
+_ZNSt6vectorIlSaIlEED2Ev.exit: ; preds = %entry
+ ret void
+}
+
+declare i32 @__cxa_atexit(void (i8*)*, i8*, i8*)
+
+define linkonce_odr void @_ZNSt6vectorIPvSaIS0_EED1Ev(%"class.std::vector"* nocapture %this) unnamed_addr align 2 {
+entry:
+ %tmp2.i.i = bitcast %"class.std::vector"* %this to i8***
+ %tmp3.i.i = load i8*** %tmp2.i.i, align 8, !tbaa !0
+ %tobool.i.i.i = icmp eq i8** %tmp3.i.i, null
+ br i1 %tobool.i.i.i, label %_ZNSt6vectorIPvSaIS0_EED2Ev.exit, label %if.then.i.i.i
+
+if.then.i.i.i: ; preds = %entry
+ %0 = bitcast i8** %tmp3.i.i to i8*
+ tail call void @_ZdlPv(i8* %0) nounwind
+ ret void
+
+_ZNSt6vectorIPvSaIS0_EED2Ev.exit: ; preds = %entry
+ ret void
+}
+
+declare void @_Z1fv()
+
+declare void @_ZNSt6vectorIPvSaIS0_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS0_S2_EERKS0_(%"class.std::vector"* nocapture %this, i8** %__position.coerce, i8** nocapture %__x) align 2
+
+declare void @_ZdlPv(i8*) nounwind
+
+declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+
+declare void @_ZSt17__throw_bad_allocv() noreturn
+
+declare noalias i8* @_Znwm(i64)
+
+declare void @_ZNSt6vectorIlSaIlEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPlS1_EERKl(%"class.std::vector"* nocapture %this, i64* %__position.coerce, i64* nocapture %__x) align 2
+
+declare void @_GLOBAL__I_a()
+
+declare %1 @llvm.uadd.with.overflow.i64(i64, i64) nounwind readnone
+
+!0 = metadata !{metadata !"any pointer", metadata !1}
+!1 = metadata !{metadata !"omnipotent char", metadata !2}
+!2 = metadata !{metadata !"Simple C/C++ TBAA", null}
+!3 = metadata !{metadata !"long", metadata !1}
More information about the llvm-commits
mailing list