Changeset View
Changeset View
Standalone View
Standalone View
llvm/test/Transforms/InstCombine/shift-add.ll
Show First 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | ; | ||||
ret i32 %r | ret i32 %r | ||||
} | } | ||||
; leading zeros for shifted constant precondition check for lshr_exact_add_negative_shift_positive | ; leading zeros for shifted constant precondition check for lshr_exact_add_negative_shift_positive | ||||
define i32 @lshr_exact_add_negative_shift_negative(i32 %x) { | define i32 @lshr_exact_add_negative_shift_negative(i32 %x) { | ||||
; CHECK-LABEL: @lshr_exact_add_negative_shift_negative( | ; CHECK-LABEL: @lshr_exact_add_negative_shift_negative( | ||||
; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], -1 | ; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], -1 | ||||
; CHECK-NEXT: [[R:%.*]] = lshr exact i32 -2, [[A]] | ; CHECK-NEXT: [[R:%.*]] = lshr exact i32 -2, [[A]] | ||||
spatel: If the constant is not negative, the ashr will get converted to lshr before we hit the new… | |||||
; CHECK-NEXT: ret i32 [[R]] | ; CHECK-NEXT: ret i32 [[R]] | ||||
; | ; | ||||
%a = add i32 %x, -1 | %a = add i32 %x, -1 | ||||
%r = lshr exact i32 -2, %a | %r = lshr exact i32 -2, %a | ||||
ret i32 %r | ret i32 %r | ||||
} | } | ||||
; exact precondition check for lshr_exact_add_negative_shift_positive | ; exact precondition check for lshr_exact_add_negative_shift_positive | ||||
define i32 @lshr_add_negative_shift_no_exact(i32 %x) { | define i32 @lshr_add_negative_shift_no_exact(i32 %x) { | ||||
; CHECK-LABEL: @lshr_add_negative_shift_no_exact( | ; CHECK-LABEL: @lshr_add_negative_shift_no_exact( | ||||
; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], -1 | ; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], -1 | ||||
; CHECK-NEXT: [[R:%.*]] = lshr i32 2, [[A]] | ; CHECK-NEXT: [[R:%.*]] = lshr i32 2, [[A]] | ||||
; CHECK-NEXT: ret i32 [[R]] | ; CHECK-NEXT: ret i32 [[R]] | ||||
; | ; | ||||
%a = add i32 %x, -1 | %a = add i32 %x, -1 | ||||
%r = lshr i32 2, %a | %r = lshr i32 2, %a | ||||
ret i32 %r | ret i32 %r | ||||
} | } | ||||
define i32 @lshr_exact_add_negative_shift_positive(i32 %x) { | define i32 @lshr_exact_add_negative_shift_positive(i32 %x) { | ||||
; CHECK-LABEL: @lshr_exact_add_negative_shift_positive( | ; CHECK-LABEL: @lshr_exact_add_negative_shift_positive( | ||||
; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], -1 | ; CHECK-NEXT: [[R:%.*]] = lshr exact i32 4, [[X:%.*]] | ||||
; CHECK-NEXT: [[R:%.*]] = lshr exact i32 2, [[A]] | |||||
; CHECK-NEXT: ret i32 [[R]] | ; CHECK-NEXT: ret i32 [[R]] | ||||
; | ; | ||||
%a = add i32 %x, -1 | %a = add i32 %x, -1 | ||||
%r = lshr exact i32 2, %a | %r = lshr exact i32 2, %a | ||||
ret i32 %r | ret i32 %r | ||||
} | } | ||||
define i8 @lshr_exact_add_negative_shift_positive_extra_use(i8 %x) { | define i8 @lshr_exact_add_negative_shift_positive_extra_use(i8 %x) { | ||||
; CHECK-LABEL: @lshr_exact_add_negative_shift_positive_extra_use( | ; CHECK-LABEL: @lshr_exact_add_negative_shift_positive_extra_use( | ||||
; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], -1 | ; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], -1 | ||||
; CHECK-NEXT: call void @use(i8 [[A]]) | ; CHECK-NEXT: call void @use(i8 [[A]]) | ||||
; CHECK-NEXT: [[R:%.*]] = lshr exact i8 64, [[A]] | ; CHECK-NEXT: [[R:%.*]] = lshr exact i8 -128, [[X]] | ||||
; CHECK-NEXT: ret i8 [[R]] | ; CHECK-NEXT: ret i8 [[R]] | ||||
; | ; | ||||
%a = add i8 %x, -1 | %a = add i8 %x, -1 | ||||
call void @use(i8 %a) | call void @use(i8 %a) | ||||
%r = lshr exact i8 64, %a | %r = lshr exact i8 64, %a | ||||
ret i8 %r | ret i8 %r | ||||
} | } | ||||
define <2 x i9> @lshr_exact_add_negative_shift_positive_vec(<2 x i9> %x) { | define <2 x i9> @lshr_exact_add_negative_shift_positive_vec(<2 x i9> %x) { | ||||
; CHECK-LABEL: @lshr_exact_add_negative_shift_positive_vec( | ; CHECK-LABEL: @lshr_exact_add_negative_shift_positive_vec( | ||||
; CHECK-NEXT: [[A:%.*]] = add <2 x i9> [[X:%.*]], <i9 -7, i9 -7> | ; CHECK-NEXT: [[R:%.*]] = lshr exact <2 x i9> <i9 -256, i9 -256>, [[X:%.*]] | ||||
; CHECK-NEXT: [[R:%.*]] = lshr exact <2 x i9> <i9 2, i9 2>, [[A]] | |||||
; CHECK-NEXT: ret <2 x i9> [[R]] | ; CHECK-NEXT: ret <2 x i9> [[R]] | ||||
; | ; | ||||
%a = add <2 x i9> %x, <i9 -7, i9 -7> | %a = add <2 x i9> %x, <i9 -7, i9 -7> | ||||
%r = lshr exact <2 x i9> <i9 2, i9 2>, %a | %r = lshr exact <2 x i9> <i9 2, i9 2>, %a | ||||
ret <2 x i9> %r | ret <2 x i9> %r | ||||
} | } | ||||
; not enough leading zeros in shift constant | ; not enough leading zeros in shift constant | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
; | ; | ||||
%a = add i32 %x, -1 | %a = add i32 %x, -1 | ||||
%r = ashr i32 -2, %a | %r = ashr i32 -2, %a | ||||
ret i32 %r | ret i32 %r | ||||
} | } | ||||
define i32 @ashr_exact_add_negative_shift_negative(i32 %x) { | define i32 @ashr_exact_add_negative_shift_negative(i32 %x) { | ||||
; CHECK-LABEL: @ashr_exact_add_negative_shift_negative( | ; CHECK-LABEL: @ashr_exact_add_negative_shift_negative( | ||||
; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], -1 | ; CHECK-NEXT: [[R:%.*]] = ashr exact i32 -4, [[X:%.*]] | ||||
; CHECK-NEXT: [[R:%.*]] = ashr exact i32 -2, [[A]] | |||||
; CHECK-NEXT: ret i32 [[R]] | ; CHECK-NEXT: ret i32 [[R]] | ||||
; | ; | ||||
%a = add i32 %x, -1 | %a = add i32 %x, -1 | ||||
%r = ashr exact i32 -2, %a | %r = ashr exact i32 -2, %a | ||||
ret i32 %r | ret i32 %r | ||||
} | } | ||||
define i8 @ashr_exact_add_negative_shift_negative_extra_use(i8 %x) { | define i8 @ashr_exact_add_negative_shift_negative_extra_use(i8 %x) { | ||||
; CHECK-LABEL: @ashr_exact_add_negative_shift_negative_extra_use( | ; CHECK-LABEL: @ashr_exact_add_negative_shift_negative_extra_use( | ||||
; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], -2 | ; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], -2 | ||||
; CHECK-NEXT: call void @use(i8 [[A]]) | ; CHECK-NEXT: call void @use(i8 [[A]]) | ||||
; CHECK-NEXT: [[R:%.*]] = ashr exact i8 -32, [[A]] | ; CHECK-NEXT: [[R:%.*]] = ashr exact i8 -128, [[X]] | ||||
; CHECK-NEXT: ret i8 [[R]] | ; CHECK-NEXT: ret i8 [[R]] | ||||
; | ; | ||||
%a = add i8 %x, -2 | %a = add i8 %x, -2 | ||||
call void @use(i8 %a) | call void @use(i8 %a) | ||||
%r = ashr exact i8 -32, %a | %r = ashr exact i8 -32, %a | ||||
ret i8 %r | ret i8 %r | ||||
} | } | ||||
define <2 x i7> @ashr_exact_add_negative_shift_negative_vec(<2 x i7> %x) { | define <2 x i7> @ashr_exact_add_negative_shift_negative_vec(<2 x i7> %x) { | ||||
; CHECK-LABEL: @ashr_exact_add_negative_shift_negative_vec( | ; CHECK-LABEL: @ashr_exact_add_negative_shift_negative_vec( | ||||
; CHECK-NEXT: [[A:%.*]] = add <2 x i7> [[X:%.*]], <i7 -5, i7 -5> | ; CHECK-NEXT: [[R:%.*]] = ashr exact <2 x i7> <i7 -64, i7 -64>, [[X:%.*]] | ||||
; CHECK-NEXT: [[R:%.*]] = ashr exact <2 x i7> <i7 -2, i7 -2>, [[A]] | |||||
; CHECK-NEXT: ret <2 x i7> [[R]] | ; CHECK-NEXT: ret <2 x i7> [[R]] | ||||
; | ; | ||||
%a = add <2 x i7> %x, <i7 -5, i7 -5> | %a = add <2 x i7> %x, <i7 -5, i7 -5> | ||||
%r = ashr exact <2 x i7> <i7 -2, i7 -2>, %a | %r = ashr exact <2 x i7> <i7 -2, i7 -2>, %a | ||||
ret <2 x i7> %r | ret <2 x i7> %r | ||||
} | } | ||||
; not enough leading ones in shift constant | ; not enough leading ones in shift constant | ||||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |
If the constant is not negative, the ashr will get converted to lshr before we hit the new transform, so this test is not providing the coverage that we want. How about something like this: