[llvm] r303379 - [InstSimplify] Make m_Not work for xor -1, X
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu May 18 13:27:32 PDT 2017
Author: ctopper
Date: Thu May 18 15:27:32 2017
New Revision: 303379
URL: http://llvm.org/viewvc/llvm-project?rev=303379&view=rev
Log:
[InstSimplify] Make m_Not work for xor -1, X
Currently m_Not only works the canonical xor X, -1 form that InstCombine produces. InstSimplify can't rely on this canonicalization.
Differential Revision: https://reviews.llvm.org/D33331
Modified:
llvm/trunk/include/llvm/IR/PatternMatch.h
llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll
Modified: llvm/trunk/include/llvm/IR/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/PatternMatch.h?rev=303379&r1=303378&r2=303379&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/IR/PatternMatch.h Thu May 18 15:27:32 2017
@@ -886,17 +886,21 @@ template <typename LHS_t> struct not_mat
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();
}
};
Modified: llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll?rev=303379&r1=303378&r2=303379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll Thu May 18 15:27:32 2017
@@ -865,3 +865,11 @@ define <2 x i8> @shl_undersized_mask_spl
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
+}
More information about the llvm-commits
mailing list