two more abs pattern and canonicalize abs pattern.
This patch handle two more pattern:
1:
define i32 @abs_canonical_6(i32 %a, i32 %b) { %tmp1 = sub i32 %a, %b %cmp = icmp sgt i32 %tmp1, -1 %tmp2 = sub i32 %b, %a %abs = select i1 %cmp, i32 %tmp1, i32 %tmp2 ret i32 %abs }
this should be |a-b|.
2:
define <2 x i8> @abs_canonical_7(<2 x i8> %a, <2 x i8 > %b) { %tmp1 = sub <2 x i8> %a, %b %cmp = icmp sgt <2 x i8> %tmp1, <i8 -1, i8 -1> %tmp2 = sub <2 x i8> %b, %a %abs = select <2 x i1> %cmp, <2 x i8> %tmp1, <2 x i8> %tmp2 ret <2 x i8> %abs }
this should be |a - b| for vector type.
3:
define i32 @abs_canonical_8(i32 %a) { ; CHECK-LABEL: @abs_canonical_8( ; CHECK-NEXT: [[TMP:%.*]] = sub i32 0, [[A:%.*]] ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[TMP]], 0 ; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[A]], i32 [[TMP]] ; CHECK-NEXT: ret i32 [[ABS]] ; %tmp = sub i32 0, %a %cmp = icmp slt i32 %tmp, 0 %abs = select i1 %cmp, i32 %a, i32 %tmp ret i32 %abs }
this should be |-a| -> |a|
Also add test cases for -|a-b|(i32 and vector), -|-a|(-|a|)