[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Oct 7 22:08:09 PDT 2004
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.262 -> 1.263
---
Log message:
Instcombine (X & FF00) + xx00 -> (X+xx00) & FF00, implementing and.ll:test27
This comes up when doing adds to bitfield elements.
---
Diffs of the changes: (+25 -0)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.262 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.263
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.262 Thu Oct 7 22:46:20 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Oct 8 00:07:56 2004
@@ -623,6 +623,31 @@
return BinaryOperator::createSub(C, X);
}
+ // (X & FF00) + xx00 -> (X+xx00) & FF00
+ if (LHS->hasOneUse() && match(LHS, m_And(m_Value(X), m_ConstantInt(C2)))) {
+ Constant *Anded = ConstantExpr::getAnd(CRHS, C2);
+ if (Anded == CRHS) {
+ // See if all bits from the first bit set in the Add RHS up are included
+ // in the mask. First, get the rightmost bit.
+ uint64_t AddRHSV = CRHS->getRawValue();
+
+ // Form a mask of all bits from the lowest bit added through the top.
+ uint64_t AddRHSHighBits = ~((AddRHSV & -AddRHSV)-1);
+ AddRHSHighBits &= (1ULL << C2->getType()->getPrimitiveSize()*8)-1;
+
+ // See if the and mask includes all of these bits.
+ uint64_t AddRHSHighBitsAnd = AddRHSHighBits & C2->getRawValue();
+
+ if (AddRHSHighBits == AddRHSHighBitsAnd) {
+ // Okay, the xform is safe. Insert the new add pronto.
+ Value *NewAdd = InsertNewInstBefore(BinaryOperator::createAdd(X, CRHS,
+ LHS->getName()), I);
+ return BinaryOperator::createAnd(NewAdd, C2);
+ }
+ }
+ }
+
+
// Try to fold constant add into select arguments.
if (SelectInst *SI = dyn_cast<SelectInst>(LHS))
if (Instruction *R = FoldBinOpIntoSelect(I, SI, this))
More information about the llvm-commits
mailing list