[llvm] [InstCombine] Fold adds + shifts with nuw flags (PR #88193)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu May 2 10:51:24 PDT 2024


================
@@ -360,8 +360,58 @@ define <3 x i14> @mul_splat_fold_vec(<3 x i14> %x) {
   ret <3 x i14> %t
 }
 
+define i32 @shl_add_lshr_flag_preservation(i32 %x, i32 %c, i32 %y) {
+; CHECK-LABEL: @shl_add_lshr_flag_preservation(
+; CHECK-NEXT:    [[TMP1:%.*]] = lshr exact i32 [[Y:%.*]], [[C:%.*]]
+; CHECK-NEXT:    [[LSHR:%.*]] = add nuw nsw i32 [[TMP1]], [[X:%.*]]
+; CHECK-NEXT:    ret i32 [[LSHR]]
+;
+  %shl = shl nuw i32 %x, %c
+  %add = add nuw nsw i32 %shl, %y
+  %lshr = lshr exact i32 %add, %c
+  ret i32 %lshr
+}
+
----------------
arsenm wrote:

Extra newline 

https://github.com/llvm/llvm-project/pull/88193


More information about the llvm-commits mailing list