[PATCH] D33331: [InstSimplify] Make m_Not work for xor -1, X

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 18 13:40:56 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL303379: [InstSimplify] Make m_Not work for xor -1, X (authored by ctopper).

Changed prior to commit:
  https://reviews.llvm.org/D33331?vs=99474&id=99488#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33331

Files:
  llvm/trunk/include/llvm/IR/PatternMatch.h
  llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll


Index: llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll
===================================================================
--- llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll
+++ llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll
@@ -865,3 +865,11 @@
   ret <2 x i8> %mask
 }
 
+define i32 @reversed_not(i32 %a) {
+; CHECK-LABEL: @reversed_not(
+; CHECK-NEXT:    ret i32 -1
+;
+  %nega = xor i32 -1, %a
+  %or = or i32 %a, %nega
+  ret i32 %or
+}
Index: llvm/trunk/include/llvm/IR/PatternMatch.h
===================================================================
--- llvm/trunk/include/llvm/IR/PatternMatch.h
+++ llvm/trunk/include/llvm/IR/PatternMatch.h
@@ -886,17 +886,21 @@
 
   template <typename OpTy> bool match(OpTy *V) {
     if (auto *O = dyn_cast<Operator>(V))
-      if (O->getOpcode() == Instruction::Xor)
-        return matchIfNot(O->getOperand(0), O->getOperand(1));
+      if (O->getOpcode() == Instruction::Xor) {
+        if (isAllOnes(O->getOperand(1)))
+          return L.match(O->getOperand(0));
+        if (isAllOnes(O->getOperand(0)))
+          return L.match(O->getOperand(1));
+      }
     return false;
   }
 
 private:
-  bool matchIfNot(Value *LHS, Value *RHS) {
-    return (isa<ConstantInt>(RHS) || isa<ConstantDataVector>(RHS) ||
+  bool isAllOnes(Value *V) {
+    return (isa<ConstantInt>(V) || isa<ConstantDataVector>(V) ||
             // FIXME: Remove CV.
-            isa<ConstantVector>(RHS)) &&
-           cast<Constant>(RHS)->isAllOnesValue() && L.match(LHS);
+            isa<ConstantVector>(V)) &&
+           cast<Constant>(V)->isAllOnesValue();
   }
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33331.99488.patch
Type: text/x-patch
Size: 1614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170518/19daf025/attachment.bin>


More information about the llvm-commits mailing list