[PATCH] D140666: [InstCombine] combine intersection for inequality icmps
chenglin.bi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 19 04:46:02 PST 2023
bcl5980 added inline comments.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:628
- if (Mask & BMask_Mixed) {
+ if (Mask & BMask_Mixed || Mask & BMask_NotMixed) {
+ // (icmp eq (A & B), C) &/| (icmp eq (A & D), E)
----------------
Is `Mask & (BMask_Mixed | BMask_NotMixed)` better?
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:682
+
+ if ((~*ConstB & ConstC) != 0 || (~*ConstD & ConstE) != 0)
+ return nullptr;
----------------
I think this code can be shared by both BMask_Mixed and BMask_NotMixed also.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:686
+ // If there is a conflict, we still have to check both sides.
if (((*ConstB & *ConstD) & (ConstC ^ ConstE)).getBoolValue())
+ return nullptr;
----------------
Is this condition the same to line 660 ? Can we add some code like:
```
if (((*ConstB & *ConstD) & (ConstC ^ ConstE)).getBoolValue())
return isMixed ? ConstantInt::get(LHS->getType(), !IsAnd) : nullptr
```
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:689
- Value *NewOr1 = Builder.CreateOr(B, D);
- Value *NewAnd = Builder.CreateAnd(A, NewOr1);
- Constant *NewOr2 = ConstantInt::get(A->getType(), ConstC | ConstE);
- return Builder.CreateICmp(NewCC, NewAnd, NewOr2);
+ Value *NewAnd1 = Builder.CreateAnd(A, ConstT);
+ Value *NewAnd2 = ConstantInt::get(A->getType(), ConstC & ConstE);
----------------
This also can be shared by select like:
```
Value *ICmpLHS = Builder.CreateBinOp(isMixed ? Instruction::Or : Instruction::And);
Value * ICmpRHS = ConstantInt::get(A->getType(), isMixed ? (ConstC | ConstE) : (ConstC & ConstE));
```
Or you can check isMixed at first:
```
Instruction::BinaryOps ICmpLHSOpcode;
APInt ICmpRHSAP;
Value* ICmpAndConflictBailout;
if (isMixed) {
ICmpLHSOpcode = Instruction::Or;
ICmpRHSAP = ConstC | ConstE;
ICmpAndConflictBailout = ConstantInt::get(LHS->getType(), !IsAnd);
} else {
ICmpLHSOpcode = Instruction::And;
ICmpRHSAP = ConstC & ConstE;
ICmpAndConflictBailout = ConstantInt::get(LHS->getType(), !IsAnd);
}
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140666/new/
https://reviews.llvm.org/D140666
More information about the llvm-commits
mailing list