[llvm] 3c3fc4c - [InstCombine] Add nsw tests for A + -B fold (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 16 07:33:21 PDT 2024
Author: Nikita Popov
Date: 2024-08-16T16:33:12+02:00
New Revision: 3c3fc4ce77da21214e1e20b8c42607b4dcdef5a7
URL: https://github.com/llvm/llvm-project/commit/3c3fc4ce77da21214e1e20b8c42607b4dcdef5a7
DIFF: https://github.com/llvm/llvm-project/commit/3c3fc4ce77da21214e1e20b8c42607b4dcdef5a7.diff
LOG: [InstCombine] Add nsw tests for A + -B fold (NFC)
Added:
Modified:
llvm/test/Transforms/InstCombine/add.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/add.ll b/llvm/test/Transforms/InstCombine/add.ll
index adb61cd4b9692..c61a9006e020d 100644
--- a/llvm/test/Transforms/InstCombine/add.ll
+++ b/llvm/test/Transforms/InstCombine/add.ll
@@ -99,16 +99,54 @@ define i32 @test3(i32 %A) {
}
; D = B + -A = B - A
-define i32 @test4(i32 %A, i32 %B) {
+define i32 @test4(i32 %A, i32 %BB) {
; CHECK-LABEL: @test4(
-; CHECK-NEXT: [[D:%.*]] = sub i32 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: [[B:%.*]] = xor i32 [[BB:%.*]], 1
+; CHECK-NEXT: [[D:%.*]] = sub i32 [[B]], [[A:%.*]]
; CHECK-NEXT: ret i32 [[D]]
;
+ %B = xor i32 %BB, 1 ; thwart complexity-based canonicalization
%C = sub i32 0, %A
%D = add i32 %B, %C
ret i32 %D
}
+define i32 @test4_both_nsw(i32 %A, i32 %BB) {
+; CHECK-LABEL: @test4_both_nsw(
+; CHECK-NEXT: [[B:%.*]] = xor i32 [[BB:%.*]], 1
+; CHECK-NEXT: [[D:%.*]] = sub i32 [[B]], [[A:%.*]]
+; CHECK-NEXT: ret i32 [[D]]
+;
+ %B = xor i32 %BB, 1 ; thwart complexity-based canonicalization
+ %C = sub nsw i32 0, %A
+ %D = add nsw i32 %B, %C
+ ret i32 %D
+}
+
+define i32 @test4_neg_nsw(i32 %A, i32 %BB) {
+; CHECK-LABEL: @test4_neg_nsw(
+; CHECK-NEXT: [[B:%.*]] = xor i32 [[BB:%.*]], 1
+; CHECK-NEXT: [[D:%.*]] = sub i32 [[B]], [[A:%.*]]
+; CHECK-NEXT: ret i32 [[D]]
+;
+ %B = xor i32 %BB, 1 ; thwart complexity-based canonicalization
+ %C = sub nsw i32 0, %A
+ %D = add i32 %B, %C
+ ret i32 %D
+}
+
+define i32 @test4_add_nsw(i32 %A, i32 %BB) {
+; CHECK-LABEL: @test4_add_nsw(
+; CHECK-NEXT: [[B:%.*]] = xor i32 [[BB:%.*]], 1
+; CHECK-NEXT: [[D:%.*]] = sub i32 [[B]], [[A:%.*]]
+; CHECK-NEXT: ret i32 [[D]]
+;
+ %B = xor i32 %BB, 1 ; thwart complexity-based canonicalization
+ %C = sub i32 0, %A
+ %D = add nsw i32 %B, %C
+ ret i32 %D
+}
+
; D = -A + B = B - A
define i32 @test5(i32 %A, i32 %B) {
; CHECK-LABEL: @test5(
More information about the llvm-commits
mailing list