[llvm] e471fda - [InstCombine] known-phi-br.ll - add multiuse of compare results to avoid predicate inverse and add negative tests
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 15 09:59:38 PDT 2022
Author: Simon Pilgrim
Date: 2022-08-15T17:57:34+01:00
New Revision: e471fdad7c32bde914dce070ec2b973e718bc40d
URL: https://github.com/llvm/llvm-project/commit/e471fdad7c32bde914dce070ec2b973e718bc40d
DIFF: https://github.com/llvm/llvm-project/commit/e471fdad7c32bde914dce070ec2b973e718bc40d.diff
LOG: [InstCombine] known-phi-br.ll - add multiuse of compare results to avoid predicate inverse and add negative tests
Feedback from D131838
Added:
Modified:
llvm/test/Transforms/InstCombine/known-phi-br.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/known-phi-br.ll b/llvm/test/Transforms/InstCombine/known-phi-br.ll
index e0dbf84919c0..395a5299a686 100644
--- a/llvm/test/Transforms/InstCombine/known-phi-br.ll
+++ b/llvm/test/Transforms/InstCombine/known-phi-br.ll
@@ -6,11 +6,14 @@
; the known bits of a phi edge based off a conditional branch feeding the phi.
;
+declare void @use(i1)
+
; TODO: %x either eq 7 or is set to 7
define i64 @limit_i64_eq_7(i64 %x) {
; CHECK-LABEL: @limit_i64_eq_7(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[X:%.*]], 7
+; CHECK-NEXT: call void @use(i1 [[CMP]])
; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]
; CHECK: body:
; CHECK-NEXT: br label [[END]]
@@ -20,6 +23,7 @@ define i64 @limit_i64_eq_7(i64 %x) {
;
entry:
%cmp = icmp eq i64 %x, 7
+ call void @use(i1 %cmp)
br i1 %cmp, label %end, label %body
body:
br label %end
@@ -32,8 +36,9 @@ end:
define i64 @limit_i64_ne_255(i64 %x) {
; CHECK-LABEL: @limit_i64_ne_255(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i64 [[X:%.*]], 255
-; CHECK-NEXT: br i1 [[CMP_NOT]], label [[END:%.*]], label [[BODY:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[X:%.*]], 255
+; CHECK-NEXT: call void @use(i1 [[CMP]])
+; CHECK-NEXT: br i1 [[CMP]], label [[BODY:%.*]], label [[END:%.*]]
; CHECK: body:
; CHECK-NEXT: br label [[END]]
; CHECK: end:
@@ -42,6 +47,7 @@ define i64 @limit_i64_ne_255(i64 %x) {
;
entry:
%cmp = icmp ne i64 %x, 255
+ call void @use(i1 %cmp)
br i1 %cmp, label %body, label %end
body:
br label %end
@@ -55,6 +61,7 @@ define i64 @limit_i64_ule_15(i64 %x) {
; CHECK-LABEL: @limit_i64_ule_15(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 16
+; CHECK-NEXT: call void @use(i1 [[CMP]])
; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]
; CHECK: body:
; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 15
@@ -66,6 +73,7 @@ define i64 @limit_i64_ule_15(i64 %x) {
;
entry:
%cmp = icmp ule i64 %x, 15
+ call void @use(i1 %cmp)
br i1 %cmp, label %end, label %body
body:
%mask = and i64 %x, 15
@@ -81,6 +89,7 @@ define i64 @limit_i64_uge_8(i64 %x) {
; CHECK-LABEL: @limit_i64_uge_8(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[X:%.*]], 7
+; CHECK-NEXT: call void @use(i1 [[CMP]])
; CHECK-NEXT: br i1 [[CMP]], label [[BODY:%.*]], label [[END:%.*]]
; CHECK: body:
; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 7
@@ -92,6 +101,7 @@ define i64 @limit_i64_uge_8(i64 %x) {
;
entry:
%cmp = icmp uge i64 %x, 8
+ call void @use(i1 %cmp)
br i1 %cmp, label %body, label %end
body:
%mask = and i64 %x, 7
@@ -107,6 +117,7 @@ define i64 @limit_i64_ult_8(i64 %x) {
; CHECK-LABEL: @limit_i64_ult_8(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 8
+; CHECK-NEXT: call void @use(i1 [[CMP]])
; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]
; CHECK: body:
; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 7
@@ -118,6 +129,7 @@ define i64 @limit_i64_ult_8(i64 %x) {
;
entry:
%cmp = icmp ult i64 %x, 8
+ call void @use(i1 %cmp)
br i1 %cmp, label %end, label %body
body:
%mask = and i64 %x, 7
@@ -133,6 +145,7 @@ define i64 @limit_i64_ugt_7(i64 %x) {
; CHECK-LABEL: @limit_i64_ugt_7(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[X:%.*]], 7
+; CHECK-NEXT: call void @use(i1 [[CMP]])
; CHECK-NEXT: br i1 [[CMP]], label [[BODY:%.*]], label [[END:%.*]]
; CHECK: body:
; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 7
@@ -144,6 +157,7 @@ define i64 @limit_i64_ugt_7(i64 %x) {
;
entry:
%cmp = icmp ugt i64 %x, 7
+ call void @use(i1 %cmp)
br i1 %cmp, label %body, label %end
body:
%mask = and i64 %x, 7
@@ -154,4 +168,62 @@ end:
ret i64 %res
}
+;
+; negative tests
+;
+; %x either ule 15 or is masked with 15
+define i64 @limit_i64_ule_15_mask3(i64 %x) {
+; CHECK-LABEL: @limit_i64_ule_15_mask3(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 16
+; CHECK-NEXT: call void @use(i1 [[CMP]])
+; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]
+; CHECK: body:
+; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 15
+; CHECK-NEXT: br label [[END]]
+; CHECK: end:
+; CHECK-NEXT: [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]
+; CHECK-NEXT: [[RES:%.*]] = and i64 [[X_MASK]], 3
+; CHECK-NEXT: ret i64 [[RES]]
+;
+entry:
+ %cmp = icmp ule i64 %x, 15
+ call void @use(i1 %cmp)
+ br i1 %cmp, label %end, label %body
+body:
+ %mask = and i64 %x, 15
+ br label %end
+end:
+ %x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]
+ %res = and i64 %x.mask, 3
+ ret i64 %res
+}
+
+; %x either ult 8 or is masked with 7
+define i64 @limit_i64_ult_8_mask1(i64 %x) {
+; CHECK-LABEL: @limit_i64_ult_8_mask1(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 8
+; CHECK-NEXT: call void @use(i1 [[CMP]])
+; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]
+; CHECK: body:
+; CHECK-NEXT: [[MASK:%.*]] = and i64 [[X]], 7
+; CHECK-NEXT: br label [[END]]
+; CHECK: end:
+; CHECK-NEXT: [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]
+; CHECK-NEXT: [[RES:%.*]] = and i64 [[X_MASK]], 1
+; CHECK-NEXT: ret i64 [[RES]]
+;
+entry:
+ %cmp = icmp ult i64 %x, 8
+ call void @use(i1 %cmp)
+ br i1 %cmp, label %end, label %body
+body:
+ %mask = and i64 %x, 7
+ br label %end
+end:
+ %x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]
+ %res = and i64 %x.mask, 1
+ ret i64 %res
+}
More information about the llvm-commits
mailing list