[llvm] [InstCombine] Keep or disjoint after folding casted bitwise logic (PR #136815)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 22 23:11:40 PDT 2025


================
@@ -1846,27 +1846,29 @@ Instruction *InstCombinerImpl::foldCastedBitwiseLogic(BinaryOperator &I) {
   if (CastOpcode != Cast1->getOpcode())
     return nullptr;
 
-  // If the source types do not match, but the casts are matching extends, we
-  // can still narrow the logic op.
-  if (SrcTy != Cast1->getSrcTy()) {
----------------
topperc wrote:

I guess you removed this check to avoid updating the later case?

```
  if ((Cast0->hasOneUse() || Cast1->hasOneUse()) &&
      shouldOptimizeCast(Cast0) && shouldOptimizeCast(Cast1)) {
    Value *NewOp = Builder.CreateBinOp(LogicOpc, Cast0Src, Cast1Src,
                                       I.getName());
    return CastInst::Create(CastOpcode, NewOp, DestTy);
  }
```

Don't we still need update the later code for the case that one of the extends has more than 1 use?

https://github.com/llvm/llvm-project/pull/136815


More information about the llvm-commits mailing list