[llvm-commits] [llvm] r122245 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp test/Transforms/InstCombine/2010-11-01-lshr-mask.ll
Duncan Sands
baldrick at free.fr
Mon Dec 20 06:47:04 PST 2010
Author: baldrick
Date: Mon Dec 20 08:47:04 2010
New Revision: 122245
URL: http://llvm.org/viewvc/llvm-project?rev=122245&view=rev
Log:
Have SimplifyBinOp dispatch Xor, Add and Sub to the corresponding methods
(they had just been forgotten before). Adding Xor causes "main" in the
existing testcase 2010-11-01-lshr-mask.ll to be hugely more simplified.
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=122245&r1=122244&r2=122245&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Mon Dec 20 08:47:04 2010
@@ -11,7 +11,9 @@
// that do not require creating new instructions. This does constant folding
// ("add i32 1, 1" -> "2") but can also handle non-constant operands, either
// returning a constant ("and i32 %x, 0" -> "0") or an already existing value
-// ("and i32 %x, %x" -> "%x").
+// ("and i32 %x, %x" -> "%x"). All operands are assumed to have already been
+// simplified: This is usually true and assuming it simplifies the logic (if
+// they have not been simplified then results are correct but maybe suboptimal).
//
//===----------------------------------------------------------------------===//
@@ -229,8 +231,9 @@
/// SimplifyAddInst - Given operands for an Add, see if we can
/// fold the result. If not, this returns null.
-Value *llvm::SimplifyAddInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
- const TargetData *TD, const DominatorTree *) {
+static Value *SimplifyAddInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
+ const TargetData *TD, const DominatorTree *DT,
+ unsigned MaxRecurse) {
if (Constant *CLHS = dyn_cast<Constant>(Op0)) {
if (Constant *CRHS = dyn_cast<Constant>(Op1)) {
Constant *Ops[] = { CLHS, CRHS };
@@ -252,6 +255,7 @@
// X + (Y - X) -> Y
// (Y - X) + X -> Y
+ // Eg: X + -X -> 0
Value *Y = 0;
if (match(Op1, m_Sub(m_Value(Y), m_Specific(Op0))) ||
match(Op0, m_Sub(m_Value(Y), m_Specific(Op1))))
@@ -274,10 +278,16 @@
return 0;
}
+Value *llvm::SimplifyAddInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
+ const TargetData *TD, const DominatorTree *DT) {
+ return ::SimplifyAddInst(Op0, Op1, isNSW, isNUW, TD, DT, RecursionLimit);
+}
+
/// SimplifySubInst - Given operands for a Sub, see if we can
/// fold the result. If not, this returns null.
-Value *llvm::SimplifySubInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
- const TargetData *TD, const DominatorTree *) {
+static Value *SimplifySubInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
+ const TargetData *TD, const DominatorTree *,
+ unsigned MaxRecurse) {
if (Constant *CLHS = dyn_cast<Constant>(Op0))
if (Constant *CRHS = dyn_cast<Constant>(Op1)) {
Constant *Ops[] = { CLHS, CRHS };
@@ -317,6 +327,11 @@
return 0;
}
+Value *llvm::SimplifySubInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
+ const TargetData *TD, const DominatorTree *DT) {
+ return ::SimplifySubInst(Op0, Op1, isNSW, isNUW, TD, DT, RecursionLimit);
+}
+
/// SimplifyAndInst - Given operands for an And, see if we can
/// fold the result. If not, this returns null.
static Value *SimplifyAndInst(Value *Op0, Value *Op1, const TargetData *TD,
@@ -826,6 +841,13 @@
switch (Opcode) {
case Instruction::And: return SimplifyAndInst(LHS, RHS, TD, DT, MaxRecurse);
case Instruction::Or: return SimplifyOrInst(LHS, RHS, TD, DT, MaxRecurse);
+ case Instruction::Xor: return SimplifyXorInst(LHS, RHS, TD, DT, MaxRecurse);
+ case Instruction::Add: return SimplifyAddInst(LHS, RHS, /* isNSW */ false,
+ /* isNUW */ false, TD, DT,
+ MaxRecurse);
+ case Instruction::Sub: return SimplifySubInst(LHS, RHS, /* isNSW */ false,
+ /* isNUW */ false, TD, DT,
+ MaxRecurse);
default:
if (Constant *CLHS = dyn_cast<Constant>(LHS))
if (Constant *CRHS = dyn_cast<Constant>(RHS)) {
Modified: llvm/trunk/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll?rev=122245&r1=122244&r2=122245&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll Mon Dec 20 08:47:04 2010
@@ -5,14 +5,16 @@
define i32 @main(i32 %argc) nounwind ssp {
entry:
%tmp3151 = trunc i32 %argc to i8
+; CHECK: %tmp3162 = shl i8 %tmp3151, 5
+; CHECK: and i8 %tmp3162, 64
+; CHECK-NOT: shl
+; CHECK-NOT: shr
%tmp3161 = or i8 %tmp3151, -17
%tmp3162 = and i8 %tmp3151, 122
%tmp3163 = xor i8 %tmp3162, -17
%tmp4114 = shl i8 %tmp3163, 6
%tmp4115 = xor i8 %tmp4114, %tmp3163
%tmp4120 = xor i8 %tmp3161, %tmp4115
-; CHECK: lshr i8 %tmp4115, 1
-; CHECK-NOT: shl i8 %tmp4126, 6
%tmp4126 = lshr i8 %tmp4120, 7
%tmp4127 = mul i8 %tmp4126, 64
%tmp4086 = zext i8 %tmp4127 to i32
More information about the llvm-commits
mailing list