[PATCH] D60396: [InstCombine] sdiv exact flag fixup
ChenZheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 7 23:00:57 PDT 2019
shchenz created this revision.
shchenz added reviewers: spatel, lebedev.ri, RKSimon.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
This is a issue found when investigate https://reviews.llvm.org/D60395.
**exact** flag is missing when opt combine ` 0 - (X sdiv C) ` -> ` (X sdiv -C)`
https://reviews.llvm.org/D60396
Files:
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/div.ll
Index: llvm/test/Transforms/InstCombine/div.ll
===================================================================
--- llvm/test/Transforms/InstCombine/div.ll
+++ llvm/test/Transforms/InstCombine/div.ll
@@ -762,7 +762,7 @@
define i32 @test_exact(i32 %x) {
; CHECK-LABEL: @test_exact(
-; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[X:%.*]], -3
+; CHECK-NEXT: [[DIV:%.*]] = sdiv exact i32 [[X:%.*]], -3
; CHECK-NEXT: ret i32 [[DIV]]
;
%div = sdiv exact i32 %x, 3
@@ -772,7 +772,7 @@
define <2 x i64> @test_exact_vec(<2 x i64> %x) {
; CHECK-LABEL: @test_exact_vec(
-; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i64> [[X:%.*]], <i64 -3, i64 -4>
+; CHECK-NEXT: [[DIV:%.*]] = sdiv exact <2 x i64> [[X:%.*]], <i64 -3, i64 -4>
; CHECK-NEXT: ret <2 x i64> [[DIV]]
;
%div = sdiv exact <2 x i64> %x, <i64 3, i64 4>
Index: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1693,8 +1693,11 @@
// 0 - (X sdiv C) -> (X sdiv -C) provided the negation doesn't overflow.
if (match(Op1, m_SDiv(m_Value(X), m_Constant(C))) && match(Op0, m_Zero()) &&
- C->isNotMinSignedValue() && !C->isOneValue())
- return BinaryOperator::CreateSDiv(X, ConstantExpr::getNeg(C));
+ C->isNotMinSignedValue() && !C->isOneValue()) {
+ auto *BO = BinaryOperator::CreateSDiv(X, ConstantExpr::getNeg(C));
+ BO->setIsExact(cast<BinaryOperator>(Op1)->isExact());
+ return BO;
+ }
// 0 - (X << Y) -> (-X << Y) when X is freely negatable.
if (match(Op1, m_Shl(m_Value(X), m_Value(Y))) && match(Op0, m_Zero()))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60396.194093.patch
Type: text/x-patch
Size: 1743 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190408/110c109f/attachment.bin>
More information about the llvm-commits
mailing list