[PATCH] D33338: [InstCombineCasts] Take in account final size when transforming sext->lshr->trunc patterns

Davide Italiano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 19 11:31:51 PDT 2017


davide added a comment.

In https://reviews.llvm.org/D33338#759486, @spatel wrote:

> Here are some tests for the smaller patterns that we might want to match:
>
>   ; FIXME: The bool bit got smeared across a wide val, but then we zero'd out those bits. This is just a zext.
>  
>   define i16 @bool_zext(i1 %x) {
>     %sext = sext i1 %x to i16
>     %hibit = lshr i16 %sext, 15
>     ret i16 %hibit
>   }
>  
>   define <2 x i8> @bool_zext_splat(<2 x i1> %x) {
>     %sext = sext <2 x i1> %x to <2 x i8>
>     %hibit = lshr <2 x i8> %sext, <i8 7, i8 7>
>     ret <2 x i8> %hibit
>   }
>  
>   ; FIXME: We could use a narrow arithmetic shift first and then zext.
>  
>   define i16 @smear_sign_and_widen(i4 %x) {
>     %sext = sext i4 %x to i16
>     %hibit = lshr i16 %sext, 12
>     ret i16 %hibit
>   }
>  
>   define <2 x i8> @smear_sign_and_widen_splat(<2 x i6> %x) {
>     %sext = sext <2 x i6> %x to <2 x i8>
>     %hibit = lshr <2 x i8> %sext, <i8 2, i8 2>
>     ret <2 x i8> %hibit
>   }
>  
>   ; FIXME: All of the replicated sign bits are wiped out by the lshr. This could be lshr+zext.
>  
>   define i16 @fake_sext(i3 %x) {
>     %sext = sext i3 %x to i16
>     %sh = lshr i16 %sext, 15
>     ret i16 %sh
>   }
>  
>   define <2 x i8> @fake_sext_splat(<2 x i3> %x) {
>     %sext = sext <2 x i3> %x to <2 x i8>
>     %sh = lshr <2 x i8> %sext, <i8 7, i8 7>
>     ret <2 x i8> %sh
>   }
>  
>


Feel free to commit these tests, I think they're good.
I'm worried about fixing the miscompile. I'll commit some tests where we get this wrong, then upload a new version of the patch so that you can take a look.


https://reviews.llvm.org/D33338





More information about the llvm-commits mailing list