Changeset View
Changeset View
Standalone View
Standalone View
llvm/test/Transforms/InstCombine/shift-add.ll
Show First 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | |||||
; CHECK-NEXT: [[R:%.*]] = shl i32 6, [[A]] | ; CHECK-NEXT: [[R:%.*]] = shl i32 6, [[A]] | ||||
; CHECK-NEXT: ret i32 [[R]] | ; CHECK-NEXT: ret i32 [[R]] | ||||
; | ; | ||||
%a = add nsw i32 %x, 5 | %a = add nsw i32 %x, 5 | ||||
%r = shl i32 6, %a | %r = shl i32 6, %a | ||||
ret i32 %r | ret i32 %r | ||||
} | } | ||||
define i32 @lshr_add_negative(i32 %x) { | |||||
; CHECK-LABEL: @lshr_add_positive( | |||||
; CHECK-NEXT: [[R:%.*]] = lshr i32 4, [[X:%.*]] | |||||
; CHECK-NEXT: ret i32 [[R]] | |||||
; | |||||
%a = add i32 %x, -1 | |||||
%r = lshr i32 2, %a | |||||
ret i32 %r | |||||
} | |||||
define i32 @ashr_exact_add_negative(i32 %x) { | |||||
; CHECK-LABEL: @ashr_exact_add_negative( | |||||
; CHECK-NEXT: [[R:%.*]] = ashr i32 -4, [[X:%.*]] | |||||
; CHECK-NEXT: ret i32 [[R]] | |||||
; | |||||
%a = add i32 %x, -1 | |||||
%r = ashr exact i32 -2, %a | |||||
ret i32 %r | |||||
} | |||||
; PR54890 | ; PR54890 | ||||
define i32 @shl_nsw_add_negative(i32 %x) { | define i32 @shl_nsw_add_negative(i32 %x) { | ||||
; CHECK-LABEL: @shl_nsw_add_negative( | ; CHECK-LABEL: @shl_nsw_add_negative( | ||||
; CHECK-NEXT: [[R:%.*]] = shl i32 1, [[X:%.*]] | ; CHECK-NEXT: [[R:%.*]] = shl i32 1, [[X:%.*]] | ||||
; CHECK-NEXT: ret i32 [[R]] | ; CHECK-NEXT: ret i32 [[R]] | ||||
; | ; | ||||
%a = add i32 %x, -1 | %a = add i32 %x, -1 | ||||
%r = shl nsw i32 2, %a | %r = shl nsw i32 2, %a | ||||
ret i32 %r | ret i32 %r | ||||
spatel: If the constant is not negative, the ashr will get converted to lshr before we hit the new… | |||||
} | } | ||||
; vectors and extra uses are allowed | ; vectors and extra uses are allowed | ||||
; nuw propagates to the new shift | ; nuw propagates to the new shift | ||||
define <2 x i8> @shl_nuw_add_negative_splat_uses(<2 x i8> %x, <2 x i8>* %p) { | define <2 x i8> @shl_nuw_add_negative_splat_uses(<2 x i8> %x, <2 x i8>* %p) { | ||||
; CHECK-LABEL: @shl_nuw_add_negative_splat_uses( | ; CHECK-LABEL: @shl_nuw_add_negative_splat_uses( | ||||
; CHECK-NEXT: [[A:%.*]] = add <2 x i8> [[X:%.*]], <i8 -2, i8 -2> | ; CHECK-NEXT: [[A:%.*]] = add <2 x i8> [[X:%.*]], <i8 -2, i8 -2> | ||||
▲ Show 20 Lines • Show All 62 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: