[PATCH] D148180: [InstCombine] Add tests for deducing constants based on condition in select; NFC
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 14 11:14:53 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdb0706b7ccce: [InstCombine] Add tests for deducing constants based on condition in select; NFC (authored by goldstein.w.n).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D148180/new/
https://reviews.llvm.org/D148180
Files:
llvm/test/Transforms/InstCombine/binop-select.ll
Index: llvm/test/Transforms/InstCombine/binop-select.ll
===================================================================
--- llvm/test/Transforms/InstCombine/binop-select.ll
+++ llvm/test/Transforms/InstCombine/binop-select.ll
@@ -5,6 +5,7 @@
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 @@
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:%.*]]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148180.513684.patch
Type: text/x-patch
Size: 2126 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230414/56cbda7a/attachment.bin>
More information about the llvm-commits
mailing list