MaskRay added a comment. Can this be moved into `RISCVTargetLowering::targetShrinkDemandedConstant`? aarch64 has a great `optimizeLogicalImm` which may give some inspiration. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D102398/new/ https://reviews.llvm.org/D102398