[llvm] r373363 - [InstCombine] Preserve 'exact' in -(X >>u 31) -> (X >>s 31) fold
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 1 10:50:09 PDT 2019
Author: lebedevri
Date: Tue Oct 1 10:50:09 2019
New Revision: 373363
URL: http://llvm.org/viewvc/llvm-project?rev=373363&view=rev
Log:
[InstCombine] Preserve 'exact' in -(X >>u 31) -> (X >>s 31) fold
https://rise4fun.com/Alive/yR4
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/trunk/test/Transforms/InstCombine/high-bit-signmask.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp?rev=373363&r1=373362&r2=373363&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Tue Oct 1 10:50:09 2019
@@ -1676,12 +1676,16 @@ Instruction *InstCombiner::visitSub(Bina
if (match(Op1, m_LShr(m_Value(X), m_APInt(ShAmt))) &&
*ShAmt == BitWidth - 1) {
Value *ShAmtOp = cast<Instruction>(Op1)->getOperand(1);
- return BinaryOperator::CreateAShr(X, ShAmtOp);
+ Instruction *NewShift = BinaryOperator::CreateAShr(X, ShAmtOp);
+ NewShift->copyIRFlags(Op1);
+ return NewShift;
}
if (match(Op1, m_AShr(m_Value(X), m_APInt(ShAmt))) &&
*ShAmt == BitWidth - 1) {
Value *ShAmtOp = cast<Instruction>(Op1)->getOperand(1);
- return BinaryOperator::CreateLShr(X, ShAmtOp);
+ Instruction *NewShift = BinaryOperator::CreateLShr(X, ShAmtOp);
+ NewShift->copyIRFlags(Op1);
+ return NewShift;
}
if (Op1->hasOneUse()) {
Modified: llvm/trunk/test/Transforms/InstCombine/high-bit-signmask.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/high-bit-signmask.ll?rev=373363&r1=373362&r2=373363&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/high-bit-signmask.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/high-bit-signmask.ll Tue Oct 1 10:50:09 2019
@@ -12,7 +12,7 @@ define i64 @t0(i64 %x) {
}
define i64 @t0_exact(i64 %x) {
; CHECK-LABEL: @t0_exact(
-; CHECK-NEXT: [[R:%.*]] = ashr i64 [[X:%.*]], 63
+; CHECK-NEXT: [[R:%.*]] = ashr exact i64 [[X:%.*]], 63
; CHECK-NEXT: ret i64 [[R]]
;
%t0 = lshr exact i64 %x, 63
@@ -30,7 +30,7 @@ define i64 @t2(i64 %x) {
}
define i64 @t3_exact(i64 %x) {
; CHECK-LABEL: @t3_exact(
-; CHECK-NEXT: [[R:%.*]] = lshr i64 [[X:%.*]], 63
+; CHECK-NEXT: [[R:%.*]] = lshr exact i64 [[X:%.*]], 63
; CHECK-NEXT: ret i64 [[R]]
;
%t0 = ashr exact i64 %x, 63
More information about the llvm-commits
mailing list