https://github.com/hanhanW commented: The canonicalization pattern is off, which leads to an invalid IR. Other parts look good, just some nits about comments. https://github.com/llvm/llvm-project/pull/129036