[llvm] [InstCombine] Fold adds + shifts with nsw and nuw flags (PR #88193)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 21 09:47:49 PDT 2024
================
@@ -360,8 +360,64 @@ define <3 x i14> @mul_splat_fold_vec(<3 x i14> %x) {
ret <3 x i14> %t
}
+define i32 @mul_times_3_div_2 (i32 %x) {
+; CHECK-LABEL: @mul_times_3_div_2(
+; CHECK-NEXT: [[TMP2:%.*]] = lshr i32 [[TMP1:%.*]], 1
+; CHECK-NEXT: [[TMP3:%.*]] = add nuw nsw i32 [[TMP2]], [[TMP1]]
+; CHECK-NEXT: ret i32 [[TMP3]]
+;
+ %2 = mul nsw nuw i32 %x, 3
+ %3 = lshr i32 %2, 1
+ ret i32 %3
+}
+
+ define i32 @shl_add_lshr (i32 %x, i32 %c, i32 %y) {
----------------
arsenm wrote:
Indentation off
https://github.com/llvm/llvm-project/pull/88193
More information about the llvm-commits
mailing list