[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
Wed Apr 12 16:03:21 PDT 2023
goldstein.w.n created this revision.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
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,32 @@
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_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.512997.patch
Type: text/x-patch
Size: 1616 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230412/ac3f4f3d/attachment.bin>
More information about the llvm-commits
mailing list