Skip to content

Commit 76f64da

Browse files
committed
Informal Change(Testing)
1 parent 0d5343e commit 76f64da

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2871,7 +2871,33 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
28712871
simplifyAndOrWithOpReplaced(Op1, Op0, Constant::getAllOnesValue(Ty),
28722872
/*SimplifyOnly*/ false, *this))
28732873
return BinaryOperator::CreateAnd(Op0, V);
2874-
2874+
// I is the 'and' instruction
2875+
if (auto *Add = dyn_cast<BinaryOperator>(I.getOperand(0))) {
2876+
if (Add->getOpcode() == Instruction::Add) {
2877+
Value *LHS = Add->getOperand(0); // should be shl
2878+
ConstantInt *AddConst = dyn_cast<ConstantInt>(Add->getOperand(1));
2879+
ConstantInt *AndConst = dyn_cast<ConstantInt>(I.getOperand(1));
2880+
if (AddConst && AndConst) {
2881+
// check if AddConst is 47 and AndConst is -32
2882+
if (AddConst->equalsInt(47) && AndConst->getSExtValue() == -32) {
2883+
// Check if LHS is shl i64 %a, 5
2884+
if (auto *Shl = dyn_cast<BinaryOperator>(LHS)) {
2885+
if (Shl->getOpcode() == Instruction::Shl) {
2886+
ConstantInt *ShlConst = dyn_cast<ConstantInt>(Shl->getOperand(1));
2887+
if (ShlConst && ShlConst->equalsInt(5)) {
2888+
// You've matched the pattern!
2889+
// Replace with: shl i64 (add i64 %a, 1), 5
2890+
IRBuilder<> Builder(&I);
2891+
Value *NewAdd = Builder.CreateAdd(Shl->getOperand(0), ConstantInt::get(I.getType(), 1));
2892+
Value *NewShl = Builder.CreateShl(NewAdd, ShlConst);
2893+
I.replaceAllUsesWith(NewShl);
2894+
}
2895+
}
2896+
}
2897+
}
2898+
}
2899+
}
2900+
}
28752901
return nullptr;
28762902
}
28772903

0 commit comments

Comments
 (0)