%s2 = sub i8 %a, %z
ret i8 %s2
}
+
+define i8 @sub_mask_lowbits(i8 %x) {
+; CHECK-LABEL: @sub_mask_lowbits(
+; CHECK-NEXT: [[A1:%.*]] = add i8 [[X:%.*]], -108
+; CHECK-NEXT: [[A2:%.*]] = and i8 [[X]], 3
+; CHECK-NEXT: [[R:%.*]] = sub i8 [[A1]], [[A2]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %a1 = add i8 %x, 148 ; 0x94
+ %a2 = and i8 %x, 3
+ %r = sub i8 %a1, %a2
+ ret i8 %r
+}
+
+define i8 @sub_not_mask_lowbits(i8 %x) {
+; CHECK-LABEL: @sub_not_mask_lowbits(
+; CHECK-NEXT: [[A1:%.*]] = add i8 [[X:%.*]], 4
+; CHECK-NEXT: [[A2:%.*]] = and i8 [[X]], 7
+; CHECK-NEXT: [[R:%.*]] = sub i8 [[A1]], [[A2]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %a1 = add i8 %x, 4
+ %a2 = and i8 %x, 7
+ %r = sub i8 %a1, %a2
+ ret i8 %r
+}
+
+define <2 x i8> @sub_mask_lowbits_splat_extra_use(<2 x i8> %x, <2 x i8>* %p) {
+; CHECK-LABEL: @sub_mask_lowbits_splat_extra_use(
+; CHECK-NEXT: [[A1:%.*]] = add <2 x i8> [[X:%.*]], <i8 -64, i8 -64>
+; CHECK-NEXT: [[A2:%.*]] = and <2 x i8> [[X]], <i8 10, i8 10>
+; CHECK-NEXT: store <2 x i8> [[A2]], <2 x i8>* [[P:%.*]], align 2
+; CHECK-NEXT: [[R:%.*]] = sub <2 x i8> [[A1]], [[A2]]
+; CHECK-NEXT: ret <2 x i8> [[R]]
+;
+ %a1 = add <2 x i8> %x, <i8 192, i8 192> ; 0xc0
+ %a2 = and <2 x i8> %x, <i8 10, i8 10> ; 0x0a
+ store <2 x i8> %a2, <2 x i8>* %p
+ %r = sub <2 x i8> %a1, %a2
+ ret <2 x i8> %r
+}