[llvm] [SimplifyCfg] Add nneg to zext for switch to table conversion (PR #147180)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 19 07:20:21 PDT 2025
dtcxzyw wrote:
> the zext can be removed if it is nneg
> > > Seems like there need to be some backend change also to remove the zext instruction see https://godbolt.org/z/Kc3MhxPdo
> >
> >
> > Might be related [b7d0c9b](https://github.com/llvm/llvm-project/commit/b7d0c9b9d8e2b5c5d6677e368e3cdaf438df294e)
>
> but what is it that make that the zext can be removed if it is nneg?
```
Legalizing node: t8: i32 = zero_extend nneg t7
Analyzing result type: i32
Legal result type
Analyzing operand: t7: i8 = add nsw t5, Constant:i8<-1>
Promote integer operand: t8: i32 = zero_extend nneg t7
Creating constant: t21: i32 = Constant<255>
Creating new node: t22: i32 = and t20, Constant:i32<255>
Replacing: t8: i32 = zero_extend nneg t7
with: t22: i32 = and t20, Constant:i32<255>
```
Besides the check for `isSExtCheaperThanZExt`, it also requires the promoted source operand to be already sign-extended. Unfortunately, we don't preserve the range for arguments in SDAG...
https://github.com/llvm/llvm-project/pull/147180
More information about the llvm-commits
mailing list