[llvm] [DAGCombiner][RISCV] Prefer to sext i32 non-negative values (PR #65984)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 13 05:15:06 PDT 2023


topperc wrote:

> > InstCombine does the same thing. 
> 
> 
> 
> I think you mean ISel. https://github.com/llvm/llvm-project/blob/231aa0f2120552b474bf86d5ff6721a6c555fdc3/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp#L6072
> 
> 
> 
> > Do we need a reverse transform to turn zext into sext explicitly? Or perhaps an isel pattern?
> 
> 
> 
> It is unsafe to turn `zext` into `sext`. Why not just prevent tuning `zext` into `sext`?
> 
> 

visitSExt in InstCombine will turn sext into zext. That code will happen before DAGCombine. The DAGCombine change will only effect sext that is created during SelectionDAG. sext that already existed in IR may get changed by InstCombine.

So my question was do we need to change zext to sext if the sign bit of the input is known to be 0 by computeKnownBits.

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


More information about the llvm-commits mailing list