[SCEVExpander] Use CreateBitOrPointerCast instead of builder (NFC).
authorFlorian Hahn <flo@fhahn.com>
Thu, 29 Sep 2022 08:24:38 +0000 (09:24 +0100)
committerFlorian Hahn <flo@fhahn.com>
Thu, 29 Sep 2022 08:24:39 +0000 (09:24 +0100)
Simplify the code by using CastInst::CreateBitOrPointerCast directly. By
not going through the builder, the temporary instruction also won't get
registered in InsertedValues & co, which means less work overall and
simplifies the clean-up.

llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

index faceb02..bc2779a 100644 (file)
@@ -1751,20 +1751,16 @@ Value *SCEVExpander::expandCodeForImpl(const SCEV *SH, Type *Ty) {
       // would accept a insertion point and return an LCSSA phi for that
       // insertion point, so there is no need to insert & remove the temporary
       // instruction.
-      Instruction *Tmp;
+      Type *ToTy;
       if (Inst->getType()->isIntegerTy())
-        Tmp = cast<Instruction>(Builder.CreateIntToPtr(
-            Inst, Inst->getType()->getPointerTo(), "tmp.lcssa.user"));
-      else {
-        assert(Inst->getType()->isPointerTy());
-        Tmp = cast<Instruction>(Builder.CreatePtrToInt(
-            Inst, Type::getInt32Ty(Inst->getContext()), "tmp.lcssa.user"));
-      }
+        ToTy = Inst->getType()->getPointerTo();
+      else
+        ToTy = Type::getInt32Ty(Inst->getContext());
+      Instruction *Tmp = CastInst::CreateBitOrPointerCast(
+          Inst, ToTy, "tmp.lcssa.user", &*Builder.GetInsertPoint());
       V = fixupLCSSAFormFor(Tmp, 0);
 
       // Clean up temporary instruction.
-      InsertedValues.erase(Tmp);
-      InsertedPostIncValues.erase(Tmp);
       Tmp->eraseFromParent();
     }
   }