[PATCH] D49382: [InstrSimplify] fold sdiv if two operands are negatived and non-overflow

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 20 01:45:36 PDT 2018


lebedev.ri accepted this revision.
lebedev.ri added a comment.
This revision is now accepted and ready to land.

Hmm, if this has issues, then i'm not seeing them.
Please commit tests now, wait 24h just in case anyone else wants to comment, and then feel free to land this.



================
Comment at: llvm/include/llvm/Analysis/ValueTracking.h:105
   /// Return true if the two given values are negation.
-  bool isKnownNegation(const Value *X, const Value *Y);
+  bool isKnownNegation(const Value *X, const Value *Y, bool checkNSW = false);
 
----------------
s/checkNSW/NeedNSW/


================
Comment at: llvm/include/llvm/Analysis/ValueTracking.h:105
   /// Return true if the two given values are negation.
-  bool isKnownNegation(const Value *X, const Value *Y);
+  bool isKnownNegation(const Value *X, const Value *Y, bool checkNSW = false);
 
----------------
lebedev.ri wrote:
> s/checkNSW/NeedNSW/
Also maybe add a comment showing two examples that are handled?


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:1085
+  // If two operands are negation and no signed overflow, return -1.
+  if (isKnownNegation(Op0, Op1, /*checkNSW=*/true))
+    return Constant::getAllOnesValue(Op0->getType());
----------------
This is also valid with `NUW` https://rise4fun.com/Alive/zb6
But we do not care because that is `0` https://godbolt.org/g/G55Np1


https://reviews.llvm.org/D49382





More information about the llvm-commits mailing list