From: Chris Lattner Date: Wed, 4 Nov 2009 05:00:12 +0000 (+0000) Subject: make IRBuilder zap "X|0" and "X&-1" when building IR, this happens X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6bffa63dfea29a525bbd38ff46d03bcc40459dca;p=oota-llvm.git make IRBuilder zap "X|0" and "X&-1" when building IR, this happens during bitfield codegen and slows down -O0 compile times by making useless IR. rdar://7362516 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86006 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index 8f26cea34cf..4652e8fb941 100644 --- a/include/llvm/Support/IRBuilder.h +++ b/include/llvm/Support/IRBuilder.h @@ -390,15 +390,21 @@ public: return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name); } Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") { - if (Constant *LC = dyn_cast(LHS)) - if (Constant *RC = dyn_cast(RHS)) + if (Constant *RC = dyn_cast(RHS)) { + if (isa(RC) && cast(RC)->isAllOnesValue()) + return LHS; // LHS & -1 -> LHS + if (Constant *LC = dyn_cast(LHS)) return Folder.CreateAnd(LC, RC); + } return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name); } Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "") { - if (Constant *LC = dyn_cast(LHS)) - if (Constant *RC = dyn_cast(RHS)) + if (Constant *RC = dyn_cast(RHS)) { + if (RC->isNullValue()) + return LHS; // LHS | 0 -> LHS + if (Constant *LC = dyn_cast(LHS)) return Folder.CreateOr(LC, RC); + } return Insert(BinaryOperator::CreateOr(LHS, RHS), Name); } Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {