[llvm] [InstCombine] Preserve the nsw flag for (X | Op01C) + Op1C --> X + (Op01C + Op1C) (PR #94586)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 7 00:59:33 PDT 2024
================
@@ -4137,5 +4137,25 @@ define i32 @fold_zext_nneg_add_const_fail2(i8 %x) {
ret i32 %r
}
+define i8 @fold_add_constant_preserve_nsw(i8 %x) {
+; CHECK-LABEL: @fold_add_constant_preserve_nsw(
+; CHECK-NEXT: [[ADD:%.*]] = add nsw i8 [[X:%.*]], -120
+; CHECK-NEXT: ret i8 [[ADD]]
+;
+ %or = or disjoint i8 %x, -128
+ %add = add nsw i8 %or, 8
+ ret i8 %add
+}
+
+define i8 @fold_add_constant_no_nsw(i8 %x) {
+; CHECK-LABEL: @fold_add_constant_no_nsw(
+; CHECK-NEXT: [[ADD:%.*]] = add i8 [[X:%.*]], 120
+; CHECK-NEXT: ret i8 [[ADD]]
+;
+ %or = or disjoint i8 %x, -128
+ %add = add nsw i8 %or, -8
+ ret i8 %add
+}
----------------
nikic wrote:
Can you please find where the existing tests for this transform are (e.g. by commenting it out and seeing what fails), and move these tests there, together with the sdiv_to_udiv test you added below)?
https://github.com/llvm/llvm-project/pull/94586
More information about the llvm-commits
mailing list