GlobalOpt runs early in the pipeline (before inlining) and complex class
hierarchies often introduce bitcasts or GEPs which weren't optimized away.
Teach it to ignore side-effect free instructions instead of depending on
other passes to remove them.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150174
91177308-0d34-0410-b5e6-
96231b3b80d8
/// destructor and can therefore be eliminated.
/// Note that we assume that other optimization passes have already simplified
/// the code so we only look for a function with a single basic block, where
/// destructor and can therefore be eliminated.
/// Note that we assume that other optimization passes have already simplified
/// the code so we only look for a function with a single basic block, where
-/// the only allowed instructions are 'ret' or 'call' to empty C++ dtor.
+/// the only allowed instructions side-effect free, 'ret' or 'call' to empty
+/// C++ dtor.
static bool cxxDtorIsEmpty(const Function &Fn,
SmallPtrSet<const Function *, 8> &CalledFunctions) {
// FIXME: We could eliminate C++ destructors if they're readonly/readnone and
static bool cxxDtorIsEmpty(const Function &Fn,
SmallPtrSet<const Function *, 8> &CalledFunctions) {
// FIXME: We could eliminate C++ destructors if they're readonly/readnone and
if (!cxxDtorIsEmpty(*CalledFn, NewCalledFunctions))
return false;
} else if (isa<ReturnInst>(*I))
if (!cxxDtorIsEmpty(*CalledFn, NewCalledFunctions))
return false;
} else if (isa<ReturnInst>(*I))
- return true;
- else
- return false;
+ return true; // We're done.
+ else if (I->mayHaveSideEffects())
+ return false; // Destructor with side effects, bail.
%0 = type { i32, void ()* }
%struct.A = type { i8 }
%0 = type { i32, void ()* }
%struct.A = type { i8 }
@a = global %struct.A zeroinitializer, align 1
@__dso_handle = external global i8*
@a = global %struct.A zeroinitializer, align 1
@__dso_handle = external global i8*
}
define linkonce_odr void @_ZN1AD1Ev(%struct.A* %this) nounwind align 2 {
}
define linkonce_odr void @_ZN1AD1Ev(%struct.A* %this) nounwind align 2 {
- call void @_ZN1AD2Ev(%struct.A* %this)
+ %t = bitcast %struct.A* %this to %struct.B*
+ call void @_ZN1BD1Ev(%struct.B* %t)
ret void
}
declare i32 @__cxa_atexit(void (i8*)*, i8*, i8*)
ret void
}
declare i32 @__cxa_atexit(void (i8*)*, i8*, i8*)
-define linkonce_odr void @_ZN1AD2Ev(%struct.A* %this) nounwind align 2 {
+define linkonce_odr void @_ZN1BD1Ev(%struct.B* %this) nounwind align 2 {