[PATCH] D31511: [InstSimplify] Don't create a constant to look for a constant. Just see if we have a constant and check its value

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 30 14:37:19 PDT 2017


craig.topper created this revision.

The code here was creating a signbit constant to do a pattern match. But creating a constant isn't free due to the uniqueing. So its more efficient to just see if a constant is being used and see if its the constant we're interested in.


https://reviews.llvm.org/D31511

Files:
  lib/Analysis/InstructionSimplify.cpp


Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -565,10 +565,10 @@
   // add nsw/nuw (xor Y, signbit), signbit --> Y
   // The no-wrapping add guarantees that the top bit will be set by the add.
   // Therefore, the xor must be clearing the already set sign bit of Y.
-  Constant *SignBit =
-      ConstantInt::get(Ty, APInt::getSignBit(Ty->getScalarSizeInBits()));
-  if ((isNSW || isNUW) && match(Op1, m_Specific(SignBit)) &&
-      match(Op0, m_Xor(m_Value(Y), m_Specific(SignBit))))
+  const APInt *C0, *C1;
+  if ((isNSW || isNUW) && match(Op1, m_APInt(C0)) &&
+      match(Op0, m_Xor(m_Value(Y), m_APInt(C1))) &&
+      C0->isSignBit() && C1->isSignBit())
     return Y;
 
   /// i1 add -> xor.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31511.93543.patch
Type: text/x-patch
Size: 850 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170330/ecfcc645/attachment.bin>


More information about the llvm-commits mailing list