[llvm] db0706b - [InstCombine] Add tests for deducing constants based on condition in select; NFC
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 14 11:14:48 PDT 2023
Author: Noah Goldstein
Date: 2023-04-14T13:14:23-05:00
New Revision: db0706b7ccceeb805c3217b4e48e6b1dddc2bc4c
URL: https://github.com/llvm/llvm-project/commit/db0706b7ccceeb805c3217b4e48e6b1dddc2bc4c
DIFF: https://github.com/llvm/llvm-project/commit/db0706b7ccceeb805c3217b4e48e6b1dddc2bc4c.diff
LOG: [InstCombine] Add tests for deducing constants based on condition in select; NFC
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D148180
Added:
Modified:
llvm/test/Transforms/InstCombine/binop-select.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/binop-select.ll b/llvm/test/Transforms/InstCombine/binop-select.ll
index 90f41a29aed57..655a34ccdea02 100644
--- a/llvm/test/Transforms/InstCombine/binop-select.ll
+++ b/llvm/test/Transforms/InstCombine/binop-select.ll
@@ -5,6 +5,7 @@ declare void @use(i32)
declare void @use_f32(float)
declare void @use_v2f16(<2 x half>)
declare void @use_v2i8(<2 x i8>)
+declare i32 @llvm.sadd.sat.i32(i32, i32)
define i32 @test1(i1 %c, i32 %x, i32 %y) {
; CHECK-LABEL: @test1(
@@ -69,6 +70,45 @@ define i32 @test5(i1 %c, i32 %x, i32 %y) {
ret i32 %add
}
+define i32 @test_sub_deduce_true(i32 %x, i32 %y) {
+; CHECK-LABEL: @test_sub_deduce_true(
+; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], 9
+; CHECK-NEXT: [[COND:%.*]] = select i1 [[C]], i32 6, i32 [[Y:%.*]]
+; CHECK-NEXT: [[SUB:%.*]] = call i32 @llvm.sadd.sat.i32(i32 [[X]], i32 [[COND]])
+; CHECK-NEXT: ret i32 [[SUB]]
+;
+ %c = icmp eq i32 %x, 9
+ %cond = select i1 %c, i32 6, i32 %y
+ %sub = call i32 @llvm.sadd.sat.i32(i32 %x, i32 %cond)
+ ret i32 %sub
+}
+
+define i32 @test_sub_deduce_true_no_const_fold(i32 %x, i32 %y) {
+; CHECK-LABEL: @test_sub_deduce_true_no_const_fold(
+; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], 9
+; CHECK-NEXT: [[COND:%.*]] = select i1 [[C]], i32 [[Y:%.*]], i32 6
+; CHECK-NEXT: [[SUB:%.*]] = call i32 @llvm.sadd.sat.i32(i32 [[X]], i32 [[COND]])
+; CHECK-NEXT: ret i32 [[SUB]]
+;
+ %c = icmp eq i32 %x, 9
+ %cond = select i1 %c, i32 %y, i32 6
+ %sub = call i32 @llvm.sadd.sat.i32(i32 %x, i32 %cond)
+ ret i32 %sub
+}
+
+define i32 @test_sub_deduce_false(i32 %x, i32 %y) {
+; CHECK-LABEL: @test_sub_deduce_false(
+; CHECK-NEXT: [[C_NOT:%.*]] = icmp eq i32 [[X:%.*]], 9
+; CHECK-NEXT: [[COND:%.*]] = select i1 [[C_NOT]], i32 7, i32 [[Y:%.*]]
+; CHECK-NEXT: [[SUB:%.*]] = call i32 @llvm.sadd.sat.i32(i32 [[X]], i32 [[COND]])
+; CHECK-NEXT: ret i32 [[SUB]]
+;
+ %c = icmp ne i32 %x, 9
+ %cond = select i1 %c, i32 %y, i32 7
+ %sub = call i32 @llvm.sadd.sat.i32(i32 %x, i32 %cond)
+ ret i32 %sub
+}
+
define i32 @test6(i1 %c, i32 %x, i32 %y) {
; CHECK-LABEL: @test6(
; CHECK-NEXT: [[COND:%.*]] = select i1 [[C:%.*]], i32 7, i32 [[X:%.*]]
More information about the llvm-commits
mailing list