[llvm] 0afe2bd - [InstCombine] Test trunc to i1 in foldSelectICmpAnd. (NFC)
Andreas Jonson via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 18 14:03:56 PST 2025
Author: Andreas Jonson
Date: 2025-02-18T23:03:49+01:00
New Revision: 0afe2bd21b06bed4d48eb88a99d13a768426359c
URL: https://github.com/llvm/llvm-project/commit/0afe2bd21b06bed4d48eb88a99d13a768426359c
DIFF: https://github.com/llvm/llvm-project/commit/0afe2bd21b06bed4d48eb88a99d13a768426359c.diff
LOG: [InstCombine] Test trunc to i1 in foldSelectICmpAnd. (NFC)
Added:
Modified:
llvm/test/Transforms/InstCombine/select-icmp-and.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/select-icmp-and.ll b/llvm/test/Transforms/InstCombine/select-icmp-and.ll
index c854a770aa74c..1218799ab3dc5 100644
--- a/llvm/test/Transforms/InstCombine/select-icmp-and.ll
+++ b/llvm/test/Transforms/InstCombine/select-icmp-and.ll
@@ -809,3 +809,97 @@ define i8 @select_bittest_to_xor(i8 %x) {
%masksel = select i1 %cmp, i8 %or, i8 %and
ret i8 %masksel
}
+
+define i8 @select_trunc_bittest_to_sub(i8 %x) {
+; CHECK-LABEL: @select_trunc_bittest_to_sub(
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[X:%.*]] to i1
+; CHECK-NEXT: [[RET:%.*]] = select i1 [[TRUNC]], i8 3, i8 4
+; CHECK-NEXT: ret i8 [[RET]]
+;
+ %trunc = trunc i8 %x to i1
+ %ret = select i1 %trunc, i8 3, i8 4
+ ret i8 %ret
+}
+
+define i8 @select_trunc_nuw_bittest_to_sub(i8 %x) {
+; CHECK-LABEL: @select_trunc_nuw_bittest_to_sub(
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc nuw i8 [[X:%.*]] to i1
+; CHECK-NEXT: [[RET:%.*]] = select i1 [[TRUNC]], i8 3, i8 4
+; CHECK-NEXT: ret i8 [[RET]]
+;
+ %trunc = trunc nuw i8 %x to i1
+ %ret = select i1 %trunc, i8 3, i8 4
+ ret i8 %ret
+}
+
+define i8 @select_trunc_nsw_bittest_to_sub(i8 %x) {
+; CHECK-LABEL: @select_trunc_nsw_bittest_to_sub(
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc nsw i8 [[X:%.*]] to i1
+; CHECK-NEXT: [[RET:%.*]] = select i1 [[TRUNC]], i8 3, i8 4
+; CHECK-NEXT: ret i8 [[RET]]
+;
+ %trunc = trunc nsw i8 %x to i1
+ %ret = select i1 %trunc, i8 3, i8 4
+ ret i8 %ret
+}
+
+define i8 @select_trunc_nuw_bittest_to_sub_extra_use(i8 %x) {
+; CHECK-LABEL: @select_trunc_nuw_bittest_to_sub_extra_use(
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc nuw i8 [[X:%.*]] to i1
+; CHECK-NEXT: call void @use1(i1 [[TRUNC]])
+; CHECK-NEXT: [[RET:%.*]] = select i1 [[TRUNC]], i8 3, i8 4
+; CHECK-NEXT: ret i8 [[RET]]
+;
+ %trunc = trunc nuw i8 %x to i1
+ call void @use1(i1 %trunc)
+ %ret = select i1 %trunc, i8 3, i8 4
+ ret i8 %ret
+}
+
+define i8 @neg_select_trunc_bittest_to_sub_extra_use(i8 %x) {
+; CHECK-LABEL: @neg_select_trunc_bittest_to_sub_extra_use(
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[X:%.*]] to i1
+; CHECK-NEXT: call void @use1(i1 [[TRUNC]])
+; CHECK-NEXT: [[RET:%.*]] = select i1 [[TRUNC]], i8 3, i8 4
+; CHECK-NEXT: ret i8 [[RET]]
+;
+ %trunc = trunc i8 %x to i1
+ call void @use1(i1 %trunc)
+ %ret = select i1 %trunc, i8 3, i8 4
+ ret i8 %ret
+}
+
+define i8 @select_trunc_nuw_bittest_to_shl_not(i8 %x) {
+; CHECK-LABEL: @select_trunc_nuw_bittest_to_shl_not(
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc nuw i8 [[X:%.*]] to i1
+; CHECK-NEXT: [[RET:%.*]] = select i1 [[TRUNC]], i8 0, i8 4
+; CHECK-NEXT: ret i8 [[RET]]
+;
+ %trunc = trunc nuw i8 %x to i1
+ %ret = select i1 %trunc, i8 0, i8 4
+ ret i8 %ret
+}
+
+define i8 @select_trunc_bittest_to_shl(i8 %x) {
+; CHECK-LABEL: @select_trunc_bittest_to_shl(
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[X:%.*]] to i1
+; CHECK-NEXT: [[RET:%.*]] = select i1 [[TRUNC]], i8 4, i8 0
+; CHECK-NEXT: ret i8 [[RET]]
+;
+ %trunc = trunc i8 %x to i1
+ %ret = select i1 %trunc, i8 4, i8 0
+ ret i8 %ret
+}
+
+define i8 @neg_select_trunc_bittest_to_shl_extra_use(i8 %x) {
+; CHECK-LABEL: @neg_select_trunc_bittest_to_shl_extra_use(
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[X:%.*]] to i1
+; CHECK-NEXT: call void @use1(i1 [[TRUNC]])
+; CHECK-NEXT: [[RET:%.*]] = select i1 [[TRUNC]], i8 4, i8 0
+; CHECK-NEXT: ret i8 [[RET]]
+;
+ %trunc = trunc i8 %x to i1
+ call void @use1(i1 %trunc)
+ %ret = select i1 %trunc, i8 4, i8 0
+ ret i8 %ret
+}
More information about the llvm-commits
mailing list