[llvm-commits] [llvm] r124657 - in /llvm/trunk: include/llvm/Support/PatternMatch.h lib/Analysis/InstructionSimplify.cpp
Duncan Sands
baldrick at free.fr
Tue Feb 1 01:06:21 PST 2011
Author: baldrick
Date: Tue Feb 1 03:06:20 2011
New Revision: 124657
URL: http://llvm.org/viewvc/llvm-project?rev=124657&view=rev
Log:
Add a m_Undef pattern for convenience. This is so that code that uses
pattern matching can also pattern match undef, creating a more uniform
style.
Modified:
llvm/trunk/include/llvm/Support/PatternMatch.h
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
Modified: llvm/trunk/include/llvm/Support/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/PatternMatch.h?rev=124657&r1=124656&r2=124657&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/Support/PatternMatch.h Tue Feb 1 03:06:20 2011
@@ -75,6 +75,16 @@
return constantint_ty<Val>();
}
+struct undef_ty {
+ template<typename ITy>
+ bool match(ITy *V) {
+ return isa<UndefValue>(V);
+ }
+};
+
+/// m_Undef() - Match an arbitrary undef constant.
+inline undef_ty m_Undef() { return undef_ty(); }
+
struct zero_ty {
template<typename ITy>
bool match(ITy *V) {
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=124657&r1=124656&r2=124657&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Feb 1 03:06:20 2011
@@ -510,7 +510,7 @@
}
// X + undef -> undef
- if (isa<UndefValue>(Op1))
+ if (match(Op1, m_Undef()))
return Op1;
// X + 0 -> X
@@ -576,7 +576,7 @@
// X - undef -> undef
// undef - X -> undef
- if (isa<UndefValue>(Op0) || isa<UndefValue>(Op1))
+ if (match(Op0, m_Undef()) || match(Op1, m_Undef()))
return UndefValue::get(Op0->getType());
// X - 0 -> X
@@ -699,7 +699,7 @@
}
// X * undef -> 0
- if (isa<UndefValue>(Op1))
+ if (match(Op1, m_Undef()))
return Constant::getNullValue(Op0->getType());
// X * 0 -> 0
@@ -771,11 +771,11 @@
bool isSigned = Opcode == Instruction::SDiv;
// X / undef -> undef
- if (isa<UndefValue>(Op1))
+ if (match(Op1, m_Undef()))
return Op1;
// undef / X -> 0
- if (isa<UndefValue>(Op0))
+ if (match(Op0, m_Undef()))
return Constant::getNullValue(Op0->getType());
// 0 / X -> 0, we don't need to preserve faults!
@@ -859,14 +859,14 @@
return ::SimplifyUDivInst(Op0, Op1, TD, DT, RecursionLimit);
}
-static Value *SimplifyFDivInst(Value *Op0, Value *Op1, const TargetData *TD,
- const DominatorTree *DT, unsigned MaxRecurse) {
+static Value *SimplifyFDivInst(Value *Op0, Value *Op1, const TargetData *,
+ const DominatorTree *, unsigned) {
// undef / X -> undef (the undef could be a snan).
- if (isa<UndefValue>(Op0))
+ if (match(Op0, m_Undef()))
return Op0;
// X / undef -> undef
- if (isa<UndefValue>(Op1))
+ if (match(Op1, m_Undef()))
return Op1;
return 0;
@@ -898,7 +898,7 @@
return Op0;
// X shift by undef -> undef because it may shift by the bitwidth.
- if (isa<UndefValue>(Op1))
+ if (match(Op1, m_Undef()))
return Op1;
// Shifting by the bitwidth or more is undefined.
@@ -930,7 +930,7 @@
return V;
// undef << X -> 0
- if (isa<UndefValue>(Op0))
+ if (match(Op0, m_Undef()))
return Constant::getNullValue(Op0->getType());
return 0;
@@ -949,7 +949,7 @@
return V;
// undef >>l X -> 0
- if (isa<UndefValue>(Op0))
+ if (match(Op0, m_Undef()))
return Constant::getNullValue(Op0->getType());
return 0;
@@ -972,7 +972,7 @@
return Op0;
// undef >>a X -> all ones
- if (isa<UndefValue>(Op0))
+ if (match(Op0, m_Undef()))
return Constant::getAllOnesValue(Op0->getType());
return 0;
@@ -999,7 +999,7 @@
}
// X & undef -> 0
- if (isa<UndefValue>(Op1))
+ if (match(Op1, m_Undef()))
return Constant::getNullValue(Op0->getType());
// X & X = X
@@ -1088,7 +1088,7 @@
}
// X | undef -> -1
- if (isa<UndefValue>(Op1))
+ if (match(Op1, m_Undef()))
return Constant::getAllOnesValue(Op0->getType());
// X | X = X
@@ -1172,7 +1172,7 @@
}
// A ^ undef -> undef
- if (isa<UndefValue>(Op1))
+ if (match(Op1, m_Undef()))
return Op1;
// A ^ 0 = A
More information about the llvm-commits
mailing list