[PATCH] D75405: [LSR] OptimizeShadowIV: Constant can be negative

Stefanos Baziotis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 29 04:37:32 PST 2020


baziotis created this revision.
baziotis added reviewers: fhahn, reames.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Instead of zero-extending the constant, sign-extend it.

Note: For some reason I can't run tests right now, but I'll get back with them.
Also, I didn't know what reviewers to add. @fhahn I suppose you're a correct one, you can
add any other you feel is appropriate.


https://reviews.llvm.org/D75405

Files:
  llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp


Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -2134,15 +2134,11 @@
 
     if (!C) continue;
 
-    // Ignore negative constants, as the code below doesn't handle them
-    // correctly. TODO: Remove this restriction.
-    if (!C->getValue().isStrictlyPositive()) continue;
-
     /* Add new PHINode. */
     PHINode *NewPH = PHINode::Create(DestTy, 2, "IV.S.", PH);
 
     /* create new increment. '++d' in above example. */
-    Constant *CFP = ConstantFP::get(DestTy, C->getZExtValue());
+    Constant *CFP = ConstantFP::get(DestTy, C->getSExtValue());
     BinaryOperator *NewIncr =
       BinaryOperator::Create(Incr->getOpcode() == Instruction::Add ?
                                Instruction::FAdd : Instruction::FSub,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75405.247437.patch
Type: text/x-patch
Size: 917 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200229/08447cc1/attachment.bin>


More information about the llvm-commits mailing list