topperc wrote: Have you look at doing this during instruction selection using the hasAllNbitUsers in RISCVISelDAGToDAG.cpp. That isn't restricted to RV64. Though it won't work across basic blocks. https://github.com/llvm/llvm-project/pull/144703