aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Support/IRBuilder.h14
1 files changed, 10 insertions, 4 deletions
diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h
index 8f26cea..4652e8f 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<Constant>(LHS))
- if (Constant *RC = dyn_cast<Constant>(RHS))
+ if (Constant *RC = dyn_cast<Constant>(RHS)) {
+ if (isa<ConstantInt>(RC) && cast<ConstantInt>(RC)->isAllOnesValue())
+ return LHS; // LHS & -1 -> LHS
+ if (Constant *LC = dyn_cast<Constant>(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<Constant>(LHS))
- if (Constant *RC = dyn_cast<Constant>(RHS))
+ if (Constant *RC = dyn_cast<Constant>(RHS)) {
+ if (RC->isNullValue())
+ return LHS; // LHS | 0 -> LHS
+ if (Constant *LC = dyn_cast<Constant>(LHS))
return Folder.CreateOr(LC, RC);
+ }
return Insert(BinaryOperator::CreateOr(LHS, RHS), Name);
}
Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {