[llvm] [DAG] Optimize Constant Xor And And Not Operation (PR #161784)
    via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Sun Oct 26 20:11:55 PDT 2025
    
    
  
manik-muk wrote:
> > > The pattern seems overly-specific. If this is a good idea, why not apply it more generally to associative expressions? Quoting my comment from #161630:
> > > > Yes it is reassociation, and should be done consistently for any associative operation, not just for this very specific case. Also this transformation is not always beneficial since it can increase register pressure if both b and c have further uses.
> > 
> > 
> > Do you think it would be beneficial to add a check that both b and c have one use before making this change? @jayfoad
> 
> Maybe, but I'd really like to know whether SelectionDAG has a general policy for that kind of thing. Does it ever try to make a sensible choice between reducing latency and increasing register pressure?
@jayfoad  I believe SelectionDAG handles this on a case by case basis and doesn't really have a generalized framework for handling this type of thing. However, I can see that in other parts of DAGCombiner.cpp, it seems to make use of the hasOneUse method to reduce the amount of instructions. on lines 10694-10697, you can see:
`    // Only fold this if the inner shift has no other uses -- if it does,
    // folding this will increase the total number of instructions.
    if (N0.getOpcode() == ISD::SRL &&
        (N0.getOperand(1) == N1 || N0.hasOneUse()) &&`
So I think adding the hasOneUse() to this example might be consistent with how this is done in the rest of the codebase.
https://github.com/llvm/llvm-project/pull/161784
    
    
More information about the llvm-commits
mailing list