Add simplify_type<const WeakVH>; simplify IndVarSimplify
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 24 Jun 2015 22:23:21 +0000 (22:23 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 24 Jun 2015 22:23:21 +0000 (22:23 +0000)
r240214 fixed some UB in IndVarSimplify, and it needed a temporary
`WeakVH` to do it.  Add `simplify_type<const WeakVH>` so that this
temporary isn't necessary.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240599 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/ValueHandle.h
lib/Transforms/Scalar/IndVarSimplify.cpp

index 355748e059770b46c86df92a643d309f36850f8f..53fa80a626aa56b459cfee03d6eac5054837c674 100644 (file)
@@ -159,11 +159,13 @@ public:
 
 // Specialize simplify_type to allow WeakVH to participate in
 // dyn_cast, isa, etc.
-template<> struct simplify_type<WeakVH> {
-  typedef Value* SimpleType;
-  static SimpleType getSimplifiedValue(WeakVH &WVH) {
-    return WVH;
-  }
+template <> struct simplify_type<WeakVH> {
+  typedef Value *SimpleType;
+  static SimpleType getSimplifiedValue(WeakVH &WVH) { return WVH; }
+};
+template <> struct simplify_type<const WeakVH> {
+  typedef Value *SimpleType;
+  static SimpleType getSimplifiedValue(const WeakVH &WVH) { return WVH; }
 };
 
 /// \brief Value handle that asserts if the Value is deleted.
index 5c9cf1a4393d1d66ca8a9b62227d0b85309dca7e..6f0375487af603f7a581b58564fa5376245e5442 100644 (file)
@@ -2013,11 +2013,10 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
 
   // Now that we're done iterating through lists, clean up any instructions
   // which are now dead.
-  while (!DeadInsts.empty()) {
-    Value *V = static_cast<Value *>(DeadInsts.pop_back_val());
-    if (Instruction *Inst = dyn_cast_or_null<Instruction>(V))
+  while (!DeadInsts.empty())
+    if (Instruction *Inst =
+            dyn_cast_or_null<Instruction>(DeadInsts.pop_back_val()))
       RecursivelyDeleteTriviallyDeadInstructions(Inst, TLI);
-  }
 
   // The Rewriter may not be used from this point on.