[llvm] 95daec6 - [ConstraintElimination] Use unsigned > 0 instead of != 0.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 22 09:56:48 PST 2021
Author: Florian Hahn
Date: 2021-02-22T17:54:36Z
New Revision: 95daec6a8497dae8fe359b8b2b363e28cb3cff23
URL: https://github.com/llvm/llvm-project/commit/95daec6a8497dae8fe359b8b2b363e28cb3cff23
DIFF: https://github.com/llvm/llvm-project/commit/95daec6a8497dae8fe359b8b2b363e28cb3cff23.diff
LOG: [ConstraintElimination] Use unsigned > 0 instead of != 0.
ICMP_NE predicates cannot be directly represented as constraint. But we
can use ICMP_UGT instead ICMP_NE for %x != 0.
See https://alive2.llvm.org/ce/z/XlLCsW
Added:
Modified:
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
llvm/test/Transforms/ConstraintElimination/ne.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 00f1c488ff57..1cfa465f4505 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -158,6 +158,10 @@ getConstraint(CmpInst::Predicate Pred, Value *Op0, Value *Op1,
return A;
}
+ if (Pred == CmpInst::ICMP_NE && match(Op1, m_Zero())) {
+ return getConstraint(CmpInst::ICMP_UGT, Op0, Op1, Value2Index, NewIndices);
+ }
+
// Only ULE and ULT predicates are supported at the moment.
if (Pred != CmpInst::ICMP_ULE && Pred != CmpInst::ICMP_ULT)
return {};
diff --git a/llvm/test/Transforms/ConstraintElimination/ne.ll b/llvm/test/Transforms/ConstraintElimination/ne.ll
index c33509131fe6..814bab108e56 100644
--- a/llvm/test/Transforms/ConstraintElimination/ne.ll
+++ b/llvm/test/Transforms/ConstraintElimination/ne.ll
@@ -1,8 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes
; RUN: opt -constraint-elimination -S %s | FileCheck %s
-define i1 @test_eq_ne(i8 %a, i8 %b) {
-; CHECK-LABEL: @test_eq_ne(
+define i1 @test_eq_ne_0(i8 %a, i8 %b) {
+; CHECK-LABEL: @test_eq_ne_0(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 0
; CHECK-NEXT: br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]]
@@ -10,14 +10,14 @@ define i1 @test_eq_ne(i8 %a, i8 %b) {
; CHECK-NEXT: [[F_1:%.*]] = icmp ne i8 [[A]], 0
; CHECK-NEXT: [[C_1:%.*]] = icmp ne i8 [[A]], 1
; CHECK-NEXT: [[C_2:%.*]] = icmp ne i8 [[A]], [[B:%.*]]
-; CHECK-NEXT: [[RES_1:%.*]] = xor i1 [[F_1]], [[C_1]]
+; CHECK-NEXT: [[RES_1:%.*]] = xor i1 false, [[C_1]]
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[RES_1]], [[C_2]]
; CHECK-NEXT: ret i1 [[RES_2]]
; CHECK: else:
; CHECK-NEXT: [[T_1:%.*]] = icmp ne i8 [[A]], 0
; CHECK-NEXT: [[C_3:%.*]] = icmp ne i8 [[A]], 1
; CHECK-NEXT: [[C_4:%.*]] = icmp ne i8 [[A]], [[B]]
-; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[T_1]], [[C_3]]
+; CHECK-NEXT: [[RES_3:%.*]] = xor i1 true, [[C_3]]
; CHECK-NEXT: [[RES_4:%.*]] = xor i1 [[RES_3]], [[C_4]]
; CHECK-NEXT: ret i1 [[RES_4]]
;
@@ -42,15 +42,15 @@ else:
ret i1 %res.4
}
-define i1 @test_ne_eq(i8 %a, i8 %b) {
-; CHECK-LABEL: @test_ne_eq(
+define i1 @test_ne_eq_0(i8 %a, i8 %b) {
+; CHECK-LABEL: @test_ne_eq_0(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 0
; CHECK-NEXT: br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]]
; CHECK: then:
; CHECK-NEXT: [[T_1:%.*]] = icmp ne i8 [[A]], 0
; CHECK-NEXT: [[C_1:%.*]] = icmp ne i8 [[A]], 1
-; CHECK-NEXT: [[RES_1:%.*]] = xor i1 [[T_1]], [[C_1]]
+; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, [[C_1]]
; CHECK-NEXT: [[C_2:%.*]] = icmp ne i8 [[A]], [[B:%.*]]
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[RES_1]], [[C_2]]
; CHECK-NEXT: [[C_3:%.*]] = icmp eq i8 [[A]], [[B]]
@@ -58,9 +58,9 @@ define i1 @test_ne_eq(i8 %a, i8 %b) {
; CHECK-NEXT: [[C_4:%.*]] = icmp eq i8 [[A]], 0
; CHECK-NEXT: [[RES_4:%.*]] = xor i1 [[RES_3]], [[C_4]]
; CHECK-NEXT: [[T_2:%.*]] = icmp ugt i8 [[A]], 0
-; CHECK-NEXT: [[RES_5:%.*]] = xor i1 [[RES_4]], [[T_2]]
+; CHECK-NEXT: [[RES_5:%.*]] = xor i1 [[RES_4]], true
; CHECK-NEXT: [[T_3:%.*]] = icmp uge i8 [[A]], 1
-; CHECK-NEXT: [[RES_6:%.*]] = xor i1 [[RES_5]], [[T_3]]
+; CHECK-NEXT: [[RES_6:%.*]] = xor i1 [[RES_5]], true
; CHECK-NEXT: [[C_5:%.*]] = icmp ugt i8 [[A]], 1
; CHECK-NEXT: [[RES_7:%.*]] = xor i1 [[RES_6]], [[C_5]]
; CHECK-NEXT: [[C_6:%.*]] = icmp sgt i8 [[A]], 0
@@ -69,7 +69,7 @@ define i1 @test_ne_eq(i8 %a, i8 %b) {
; CHECK: else:
; CHECK-NEXT: [[F_1:%.*]] = icmp ne i8 [[A]], 0
; CHECK-NEXT: [[C_7:%.*]] = icmp ne i8 [[A]], 1
-; CHECK-NEXT: [[RES_9:%.*]] = xor i1 [[F_1]], [[C_7]]
+; CHECK-NEXT: [[RES_9:%.*]] = xor i1 false, [[C_7]]
; CHECK-NEXT: [[C_8:%.*]] = icmp ne i8 [[A]], [[B]]
; CHECK-NEXT: [[RES_10:%.*]] = xor i1 [[RES_9]], [[C_8]]
; CHECK-NEXT: [[C_9:%.*]] = icmp eq i8 [[A]], [[B]]
@@ -146,3 +146,149 @@ else:
ret i1 %res.16
}
+
+define i1 @test_eq_ne_1(i8 %a, i8 %b) {
+; CHECK-LABEL: @test_eq_ne_1(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 1
+; CHECK-NEXT: br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK: then:
+; CHECK-NEXT: [[F_1:%.*]] = icmp ne i8 [[A]], 0
+; CHECK-NEXT: [[C_1:%.*]] = icmp ne i8 [[A]], 1
+; CHECK-NEXT: [[C_2:%.*]] = icmp ne i8 [[A]], [[B:%.*]]
+; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, [[C_1]]
+; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[RES_1]], [[C_2]]
+; CHECK-NEXT: ret i1 [[RES_2]]
+; CHECK: else:
+; CHECK-NEXT: [[T_1:%.*]] = icmp ne i8 [[A]], 0
+; CHECK-NEXT: [[C_3:%.*]] = icmp ne i8 [[A]], 1
+; CHECK-NEXT: [[C_4:%.*]] = icmp ne i8 [[A]], [[B]]
+; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[T_1]], [[C_3]]
+; CHECK-NEXT: [[RES_4:%.*]] = xor i1 [[RES_3]], [[C_4]]
+; CHECK-NEXT: ret i1 [[RES_4]]
+;
+entry:
+ %cmp = icmp eq i8 %a, 1
+ br i1 %cmp, label %then, label %else
+
+then:
+ %f.1 = icmp ne i8 %a, 0
+ %c.1 = icmp ne i8 %a, 1
+ %c.2 = icmp ne i8 %a, %b
+ %res.1 = xor i1 %f.1, %c.1
+ %res.2 = xor i1 %res.1, %c.2
+ ret i1 %res.2
+
+else:
+ %t.1 = icmp ne i8 %a, 0
+ %c.3 = icmp ne i8 %a, 1
+ %c.4 = icmp ne i8 %a, %b
+ %res.3 = xor i1 %t.1, %c.3
+ %res.4 = xor i1 %res.3, %c.4
+ ret i1 %res.4
+}
+
+define i1 @test_ne_eq_1(i8 %a, i8 %b) {
+; CHECK-LABEL: @test_ne_eq_1(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 1
+; CHECK-NEXT: br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK: then:
+; CHECK-NEXT: [[T_1:%.*]] = icmp ne i8 [[A]], 1
+; CHECK-NEXT: [[C_1:%.*]] = icmp ne i8 [[A]], 0
+; CHECK-NEXT: [[RES_1:%.*]] = xor i1 [[T_1]], [[C_1]]
+; CHECK-NEXT: [[C_2:%.*]] = icmp ne i8 [[A]], [[B:%.*]]
+; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[RES_1]], [[C_2]]
+; CHECK-NEXT: [[C_3:%.*]] = icmp eq i8 [[A]], [[B]]
+; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[RES_2]], [[C_3]]
+; CHECK-NEXT: [[C_4:%.*]] = icmp eq i8 [[A]], 0
+; CHECK-NEXT: [[RES_4:%.*]] = xor i1 [[RES_3]], [[C_4]]
+; CHECK-NEXT: [[C_5:%.*]] = icmp ugt i8 [[A]], 0
+; CHECK-NEXT: [[RES_5:%.*]] = xor i1 [[RES_4]], [[C_5]]
+; CHECK-NEXT: [[C_6:%.*]] = icmp uge i8 [[A]], 1
+; CHECK-NEXT: [[RES_6:%.*]] = xor i1 [[RES_5]], [[C_6]]
+; CHECK-NEXT: [[C_7:%.*]] = icmp ugt i8 [[A]], 1
+; CHECK-NEXT: [[RES_7:%.*]] = xor i1 [[RES_6]], [[C_5]]
+; CHECK-NEXT: [[C_8:%.*]] = icmp sgt i8 [[A]], 0
+; CHECK-NEXT: [[RES_8:%.*]] = xor i1 [[RES_7]], [[C_6]]
+; CHECK-NEXT: ret i1 [[RES_8]]
+; CHECK: else:
+; CHECK-NEXT: [[T_2:%.*]] = icmp ne i8 [[A]], 0
+; CHECK-NEXT: [[C_9:%.*]] = icmp ne i8 [[A]], 1
+; CHECK-NEXT: [[RES_9:%.*]] = xor i1 true, [[C_9]]
+; CHECK-NEXT: [[C_10:%.*]] = icmp ne i8 [[A]], [[B]]
+; CHECK-NEXT: [[RES_10:%.*]] = xor i1 [[RES_9]], [[C_10]]
+; CHECK-NEXT: [[C_11:%.*]] = icmp eq i8 [[A]], [[B]]
+; CHECK-NEXT: [[RES_11:%.*]] = xor i1 [[RES_10]], [[C_11]]
+; CHECK-NEXT: [[F_1:%.*]] = icmp eq i8 [[A]], 0
+; CHECK-NEXT: [[RES_12:%.*]] = xor i1 [[RES_11]], [[F_1]]
+; CHECK-NEXT: [[T_3:%.*]] = icmp ugt i8 [[A]], 0
+; CHECK-NEXT: [[RES_13:%.*]] = xor i1 [[RES_12]], true
+; CHECK-NEXT: [[T_4:%.*]] = icmp uge i8 [[A]], 1
+; CHECK-NEXT: [[RES_14:%.*]] = xor i1 [[RES_13]], true
+; CHECK-NEXT: [[F_2:%.*]] = icmp ugt i8 [[A]], 1
+; CHECK-NEXT: [[RES_15:%.*]] = xor i1 [[RES_14]], false
+; CHECK-NEXT: [[C_12:%.*]] = icmp sgt i8 [[A]], 0
+; CHECK-NEXT: [[RES_16:%.*]] = xor i1 [[RES_15]], [[C_12]]
+; CHECK-NEXT: ret i1 [[RES_16]]
+;
+entry:
+ %cmp = icmp ne i8 %a, 1
+ br i1 %cmp, label %then, label %else
+
+then:
+ %t.1 = icmp ne i8 %a, 1
+ %c.1 = icmp ne i8 %a, 0
+ %res.1 = xor i1 %t.1, %c.1
+
+ %c.2 = icmp ne i8 %a, %b
+ %res.2 = xor i1 %res.1, %c.2
+
+ %c.3 = icmp eq i8 %a, %b
+ %res.3 = xor i1 %res.2, %c.3
+
+ %c.4 = icmp eq i8 %a, 0
+ %res.4 = xor i1 %res.3, %c.4
+
+ %c.5 = icmp ugt i8 %a, 0
+ %res.5 = xor i1 %res.4, %c.5
+
+ %c.6 = icmp uge i8 %a, 1
+ %res.6 = xor i1 %res.5, %c.6
+
+ %c.7 = icmp ugt i8 %a, 1
+ %res.7 = xor i1 %res.6, %c.5
+
+ %c.8 = icmp sgt i8 %a, 0
+ %res.8 = xor i1 %res.7, %c.6
+
+ ret i1 %res.8
+
+else:
+ %t.2 = icmp ne i8 %a, 0
+ %c.9 = icmp ne i8 %a, 1
+ %res.9 = xor i1 %t.2, %c.9
+
+ %c.10 = icmp ne i8 %a, %b
+ %res.10 = xor i1 %res.9, %c.10
+
+ %c.11 = icmp eq i8 %a, %b
+ %res.11 = xor i1 %res.10, %c.11
+
+ %f.1 = icmp eq i8 %a, 0
+ %res.12 = xor i1 %res.11, %f.1
+
+ %t.3 = icmp ugt i8 %a, 0
+ %res.13 = xor i1 %res.12, %t.3
+
+ %t.4 = icmp uge i8 %a, 1
+ %res.14 = xor i1 %res.13, %t.4
+
+ %f.2 = icmp ugt i8 %a, 1
+ %res.15 = xor i1 %res.14, %f.2
+
+ %c.12 = icmp sgt i8 %a, 0
+ %res.16 = xor i1 %res.15, %c.12
+
+ ret i1 %res.16
+}
More information about the llvm-commits
mailing list