[PATCH] D85341: [ConstraintElimination] support sub nuw
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 5 12:30:04 PDT 2020
fhahn created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
fhahn requested review of this revision.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D85341
Files:
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
llvm/test/Transforms/ConstraintElimination/sub-nuw.ll
Index: llvm/test/Transforms/ConstraintElimination/sub-nuw.ll
===================================================================
--- llvm/test/Transforms/ConstraintElimination/sub-nuw.ll
+++ llvm/test/Transforms/ConstraintElimination/sub-nuw.ll
@@ -20,10 +20,10 @@
; CHECK-NEXT: call void @use(i1 [[T_2]])
; CHECK-NEXT: [[START_3:%.*]] = sub nuw i8 [[START]], 3
; CHECK-NEXT: [[T_3:%.*]] = icmp ult i8 [[START_3]], [[HIGH]]
-; CHECK-NEXT: call void @use(i1 [[T_3]])
+; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[START_4:%.*]] = sub nuw i8 [[START]], 4
; CHECK-NEXT: [[C_4:%.*]] = icmp ult i8 [[START_4]], [[HIGH]]
-; CHECK-NEXT: call void @use(i1 [[C_4]])
+; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: ret void
;
entry:
@@ -68,16 +68,16 @@
; CHECK-NEXT: call void @use(i1 [[T_1]])
; CHECK-NEXT: [[START_2:%.*]] = sub nuw i8 [[START]], 2
; CHECK-NEXT: [[T_2:%.*]] = icmp ule i8 [[START_2]], [[HIGH]]
-; CHECK-NEXT: call void @use(i1 [[T_2]])
+; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[START_3:%.*]] = sub nuw i8 [[START]], 3
; CHECK-NEXT: [[T_3:%.*]] = icmp ule i8 [[START_3]], [[HIGH]]
-; CHECK-NEXT: call void @use(i1 [[T_3]])
+; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[START_4:%.*]] = sub nuw i8 [[START]], 4
; CHECK-NEXT: [[T_4:%.*]] = icmp ule i8 [[START_4]], [[HIGH]]
-; CHECK-NEXT: call void @use(i1 [[T_4]])
+; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[START_5:%.*]] = sub nuw i8 [[START]], 5
; CHECK-NEXT: [[C_5:%.*]] = icmp ule i8 [[START_5]], [[HIGH]]
-; CHECK-NEXT: call void @use(i1 [[C_5]])
+; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: ret void
;
entry:
@@ -127,16 +127,16 @@
; CHECK-NEXT: call void @use(i1 [[F_1]])
; CHECK-NEXT: [[START_2:%.*]] = sub nuw i8 [[START]], 2
; CHECK-NEXT: [[F_2:%.*]] = icmp ugt i8 [[START_2]], [[HIGH]]
-; CHECK-NEXT: call void @use(i1 [[F_2]])
+; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: [[START_3:%.*]] = sub nuw i8 [[START]], 3
; CHECK-NEXT: [[F_3:%.*]] = icmp ugt i8 [[START_3]], [[HIGH]]
-; CHECK-NEXT: call void @use(i1 [[F_3]])
+; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: [[START_4:%.*]] = sub nuw i8 [[START]], 4
; CHECK-NEXT: [[F_4:%.*]] = icmp ugt i8 [[START_4]], [[HIGH]]
-; CHECK-NEXT: call void @use(i1 [[F_4]])
+; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: [[START_5:%.*]] = sub nuw i8 [[START]], 5
; CHECK-NEXT: [[C_5:%.*]] = icmp ugt i8 [[START_5]], [[HIGH]]
-; CHECK-NEXT: call void @use(i1 [[C_5]])
+; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: ret void
;
entry:
@@ -193,13 +193,13 @@
; CHECK-NEXT: call void @use(i1 [[F_2]])
; CHECK-NEXT: [[START_3:%.*]] = sub nuw i8 [[START]], 3
; CHECK-NEXT: [[F_3:%.*]] = icmp uge i8 [[START_3]], [[HIGH]]
-; CHECK-NEXT: call void @use(i1 [[F_3]])
+; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: [[START_4:%.*]] = sub nuw i8 [[START]], 4
; CHECK-NEXT: [[C_4:%.*]] = icmp uge i8 [[START_4]], [[HIGH]]
-; CHECK-NEXT: call void @use(i1 [[C_4]])
+; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: [[START_5:%.*]] = sub nuw i8 [[START]], 5
; CHECK-NEXT: [[C_5:%.*]] = icmp uge i8 [[START_5]], [[HIGH]]
-; CHECK-NEXT: call void @use(i1 [[C_5]])
+; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: ret void
;
entry:
Index: llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -55,6 +55,10 @@
ConstantInt *CI;
if (match(V, m_NUWAdd(m_Value(Op0), m_ConstantInt(CI))))
return {{CI->getSExtValue(), Op0}};
+
+ if (match(V, m_NUWSub(m_Value(Op0), m_ConstantInt(CI))))
+ return {{-1 * CI->getSExtValue(), Op0}};
+
return {{0, V}};
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85341.283340.patch
Type: text/x-patch
Size: 3954 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200805/37a068d0/attachment.bin>
More information about the llvm-commits
mailing list