[llvm] 65d4354 - [InstCombine] add more tests for nsw propagation; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 24 11:43:48 PDT 2022


Author: Sanjay Patel
Date: 2022-03-24T14:40:59-04:00
New Revision: 65d43541499822cc4c0c160b32be34c48dda4939

URL: https://github.com/llvm/llvm-project/commit/65d43541499822cc4c0c160b32be34c48dda4939
DIFF: https://github.com/llvm/llvm-project/commit/65d43541499822cc4c0c160b32be34c48dda4939.diff

LOG: [InstCombine] add more tests for nsw propagation; NFC

Follow-up as suggested with b6efd2510a1efaf2 -
show a couple of examples of general subtraction
(the earlier patch was all negations).

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/nsw.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/nsw.ll b/llvm/test/Transforms/InstCombine/nsw.ll
index 4842a2139e120..f7b8c83b5111e 100644
--- a/llvm/test/Transforms/InstCombine/nsw.ll
+++ b/llvm/test/Transforms/InstCombine/nsw.ll
@@ -226,3 +226,29 @@ define i8 @neg_sub_sub2(i16 %a, i16 %b) {
   %e = sub nsw i8 0, %d
   ret i8 %e
 }
+
+; Must not propagate nsw.
+
+define i32 @sub_sub0_nsw_nsw(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @sub_sub0_nsw_nsw(
+; CHECK-NEXT:    [[TMP1:%.*]] = add i32 [[B:%.*]], [[C:%.*]]
+; CHECK-NEXT:    [[S2:%.*]] = sub i32 [[A:%.*]], [[TMP1]]
+; CHECK-NEXT:    ret i32 [[S2]]
+;
+  %s1 = sub nsw i32 %a, %b
+  %s2 = sub nsw i32 %s1, %c
+  ret i32 %s2
+}
+
+; Must not propagate nsw.
+
+define i32 @sub_sub1_nsw_nsw(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @sub_sub1_nsw_nsw(
+; CHECK-NEXT:    [[S1_NEG:%.*]] = sub i32 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT:    [[S2:%.*]] = add i32 [[S1_NEG]], [[C:%.*]]
+; CHECK-NEXT:    ret i32 [[S2]]
+;
+  %s1 = sub nsw i32 %a, %b
+  %s2 = sub nsw i32 %c, %s1
+  ret i32 %s2
+}


        


More information about the llvm-commits mailing list