[PATCH] D47117: [CVP][NFCI] Refactor truncated binary operator creation out of processUDivOrURem()

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 20 02:11:53 PDT 2018


lebedev.ri created this revision.
lebedev.ri added reviewers: spatel, jlebar, sanjoy, anna, davide, reames.

Repository:
  rL LLVM

https://reviews.llvm.org/D47117

Files:
  lib/Transforms/Scalar/CorrelatedValuePropagation.cpp


Index: lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
===================================================================
--- lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -493,6 +493,21 @@
   return true;
 }
 
+// NOTE: do not forget to call Instr->eraseFromParent(); afterwards!
+BinaryOperator *CreateTruncatedBO(BinaryOperator *Instr, unsigned NewWidth) {
+  auto *TruncTy = Type::getIntNTy(Instr->getContext(), NewWidth);
+  auto *LHS = CastInst::Create(Instruction::Trunc, Instr->getOperand(0),
+                               TruncTy, Instr->getName() + ".lhs.trunc", Instr);
+  auto *RHS = CastInst::Create(Instruction::Trunc, Instr->getOperand(1),
+                               TruncTy, Instr->getName() + ".rhs.trunc", Instr);
+  auto *BO = BinaryOperator::Create(Instr->getOpcode(), LHS, RHS,
+                                    Instr->getName(), Instr);
+  auto *Zext = CastInst::Create(Instruction::ZExt, BO, Instr->getType(),
+                                Instr->getName() + ".zext", Instr);
+  Instr->replaceAllUsesWith(Zext);
+  return BO;
+}
+
 /// Try to shrink a udiv/urem's width down to the smallest power of two that's
 /// sufficient to contain its operands.
 static bool processUDivOrURem(BinaryOperator *Instr, LazyValueInfo *LVI) {
@@ -518,19 +533,9 @@
     return false;
 
   ++NumUDivs;
-  auto *TruncTy = Type::getIntNTy(Instr->getContext(), NewWidth);
-  auto *LHS = CastInst::Create(Instruction::Trunc, Instr->getOperand(0), TruncTy,
-                               Instr->getName() + ".lhs.trunc", Instr);
-  auto *RHS = CastInst::Create(Instruction::Trunc, Instr->getOperand(1), TruncTy,
-                               Instr->getName() + ".rhs.trunc", Instr);
-  auto *BO =
-      BinaryOperator::Create(Instr->getOpcode(), LHS, RHS, Instr->getName(), Instr);
-  auto *Zext = CastInst::Create(Instruction::ZExt, BO, Instr->getType(),
-                                Instr->getName() + ".zext", Instr);
+  auto *BO = CreateTruncatedBO(Instr, NewWidth);
   if (BO->getOpcode() == Instruction::UDiv)
     BO->setIsExact(Instr->isExact());
-
-  Instr->replaceAllUsesWith(Zext);
   Instr->eraseFromParent();
   return true;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47117.147704.patch
Type: text/x-patch
Size: 2236 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180520/24338b7a/attachment.bin>


More information about the llvm-commits mailing list