@@ -2731,12 +2731,14 @@ define i32 @floor_sdiv_wrong_op(i32 %x, i32 %y) {
2731
2731
ret i32 %r
2732
2732
}
2733
2733
2734
+ ; (X s>> (BW - 1)) + (zext (X s> 0)) --> (X s>> (BW - 1)) | (zext (X != 0))
2735
+
2734
2736
define i8 @signum_i8_i8 (i8 %x ) {
2735
2737
; CHECK-LABEL: @signum_i8_i8(
2736
- ; CHECK-NEXT: [[SGT0 :%.*]] = icmp sgt i8 [[X:%.*]], 0
2737
- ; CHECK-NEXT: [[ZGT0 :%.*]] = zext i1 [[SGT0]] to i8
2738
- ; CHECK-NEXT: [[SIGNBIT :%.*]] = ashr i8 [[X]], 7
2739
- ; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[SIGNBIT]], [[ZGT0 ]]
2738
+ ; CHECK-NEXT: [[SIGNBIT :%.*]] = ashr i8 [[X:%.*]], 7
2739
+ ; CHECK-NEXT: [[ISNOTNULL :%.*]] = icmp ne i8 [[X]], 0
2740
+ ; CHECK-NEXT: [[ISNOTNULL_ZEXT :%.*]] = zext i1 [[ISNOTNULL]] to i8
2741
+ ; CHECK-NEXT: [[R:%.*]] = or i8 [[SIGNBIT]], [[ISNOTNULL_ZEXT ]]
2740
2742
; CHECK-NEXT: ret i8 [[R]]
2741
2743
;
2742
2744
%sgt0 = icmp sgt i8 %x , 0
@@ -2746,13 +2748,15 @@ define i8 @signum_i8_i8(i8 %x) {
2746
2748
ret i8 %r
2747
2749
}
2748
2750
2751
+ ; extra use of shift is ok
2752
+
2749
2753
define i8 @signum_i8_i8_use1 (i8 %x ) {
2750
2754
; CHECK-LABEL: @signum_i8_i8_use1(
2751
- ; CHECK-NEXT: [[SGT0:%.*]] = icmp sgt i8 [[X:%.*]], 0
2752
- ; CHECK-NEXT: [[ZGT0:%.*]] = zext i1 [[SGT0]] to i8
2753
- ; CHECK-NEXT: [[SIGNBIT:%.*]] = ashr i8 [[X]], 7
2755
+ ; CHECK-NEXT: [[SIGNBIT:%.*]] = ashr i8 [[X:%.*]], 7
2754
2756
; CHECK-NEXT: call void @use(i8 [[SIGNBIT]])
2755
- ; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[SIGNBIT]], [[ZGT0]]
2757
+ ; CHECK-NEXT: [[ISNOTNULL:%.*]] = icmp ne i8 [[X]], 0
2758
+ ; CHECK-NEXT: [[ISNOTNULL_ZEXT:%.*]] = zext i1 [[ISNOTNULL]] to i8
2759
+ ; CHECK-NEXT: [[R:%.*]] = or i8 [[SIGNBIT]], [[ISNOTNULL_ZEXT]]
2756
2760
; CHECK-NEXT: ret i8 [[R]]
2757
2761
;
2758
2762
%sgt0 = icmp sgt i8 %x , 0
@@ -2763,6 +2767,8 @@ define i8 @signum_i8_i8_use1(i8 %x) {
2763
2767
ret i8 %r
2764
2768
}
2765
2769
2770
+ ; negative test
2771
+
2766
2772
define i8 @signum_i8_i8_use2 (i8 %x ) {
2767
2773
; CHECK-LABEL: @signum_i8_i8_use2(
2768
2774
; CHECK-NEXT: [[SGT0:%.*]] = icmp sgt i8 [[X:%.*]], 0
@@ -2780,6 +2786,8 @@ define i8 @signum_i8_i8_use2(i8 %x) {
2780
2786
ret i8 %r
2781
2787
}
2782
2788
2789
+ ; negative test
2790
+
2783
2791
define i8 @signum_i8_i8_use3 (i8 %x ) {
2784
2792
; CHECK-LABEL: @signum_i8_i8_use3(
2785
2793
; CHECK-NEXT: [[SGT0:%.*]] = icmp sgt i8 [[X:%.*]], 0
@@ -2797,12 +2805,15 @@ define i8 @signum_i8_i8_use3(i8 %x) {
2797
2805
ret i8 %r
2798
2806
}
2799
2807
2808
+ ; poison/undef is ok to propagate in shift amount
2809
+ ; complexity canonicalization guarantees that shift is op0 of add
2810
+
2800
2811
define <2 x i5 > @signum_v2i5_v2i5 (<2 x i5 > %x ) {
2801
2812
; CHECK-LABEL: @signum_v2i5_v2i5(
2802
- ; CHECK-NEXT: [[SGT0 :%.*]] = icmp sgt <2 x i5> [[X:%.*]], zeroinitializer
2803
- ; CHECK-NEXT: [[ZGT0 :%.*]] = zext <2 x i1 > [[SGT0]] to <2 x i5>
2804
- ; CHECK-NEXT: [[SIGNBIT :%.*]] = ashr <2 x i5 > [[X]], <i5 4, i5 poison >
2805
- ; CHECK-NEXT: [[R:%.*]] = add <2 x i5> [[SIGNBIT]], [[ZGT0 ]]
2813
+ ; CHECK-NEXT: [[SIGNBIT :%.*]] = ashr <2 x i5> [[X:%.*]], <i5 4, i5 poison>
2814
+ ; CHECK-NEXT: [[ISNOTNULL :%.*]] = icmp ne <2 x i5 > [[X]], zeroinitializer
2815
+ ; CHECK-NEXT: [[ISNOTNULL_ZEXT :%.*]] = zext <2 x i1 > [[ISNOTNULL]] to <2 x i5>
2816
+ ; CHECK-NEXT: [[R:%.*]] = or <2 x i5> [[SIGNBIT]], [[ISNOTNULL_ZEXT ]]
2806
2817
; CHECK-NEXT: ret <2 x i5> [[R]]
2807
2818
;
2808
2819
%sgt0 = icmp sgt <2 x i5 > %x , zeroinitializer
@@ -2812,6 +2823,8 @@ define <2 x i5> @signum_v2i5_v2i5(<2 x i5> %x) {
2812
2823
ret <2 x i5 > %r
2813
2824
}
2814
2825
2826
+ ; negative test
2827
+
2815
2828
define i8 @signum_i8_i8_wrong_sh_amt (i8 %x ) {
2816
2829
; CHECK-LABEL: @signum_i8_i8_wrong_sh_amt(
2817
2830
; CHECK-NEXT: [[SGT0:%.*]] = icmp sgt i8 [[X:%.*]], 0
@@ -2827,6 +2840,8 @@ define i8 @signum_i8_i8_wrong_sh_amt(i8 %x) {
2827
2840
ret i8 %r
2828
2841
}
2829
2842
2843
+ ; negative test
2844
+
2830
2845
define i8 @signum_i8_i8_wrong_ext (i8 %x ) {
2831
2846
; CHECK-LABEL: @signum_i8_i8_wrong_ext(
2832
2847
; CHECK-NEXT: [[SGT0:%.*]] = icmp sgt i8 [[X:%.*]], 0
@@ -2842,6 +2857,8 @@ define i8 @signum_i8_i8_wrong_ext(i8 %x) {
2842
2857
ret i8 %r
2843
2858
}
2844
2859
2860
+ ; negative test
2861
+
2845
2862
define i8 @signum_i8_i8_wrong_pred (i8 %x ) {
2846
2863
; CHECK-LABEL: @signum_i8_i8_wrong_pred(
2847
2864
; CHECK-NEXT: [[SGT0:%.*]] = icmp sgt i8 [[X:%.*]], -1
0 commit comments