[PATCH] D84971: [ValueTracking]
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 12:30:44 PDT 2020
craig.topper created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
craig.topper requested review of this revision.
https://reviews.llvm.org/D84971
Files:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/InstCombine/abs-intrinsic.ll
Index: llvm/test/Transforms/InstCombine/abs-intrinsic.ll
===================================================================
--- llvm/test/Transforms/InstCombine/abs-intrinsic.ll
+++ llvm/test/Transforms/InstCombine/abs-intrinsic.ll
@@ -51,3 +51,18 @@
%and2 = and i32 %abs, -4
ret i32 %and2
}
+
+; Make sure we infer this add doesn't overflow. The input to the abs has 3
+; sign bits, the abs reduces this to 2 sign bits.
+define i32 @abs_signbits(i30 %x) {
+; CHECK-LABEL: @abs_signbits(
+; CHECK-NEXT: [[AND:%.*]] = sext i30 [[X:%.*]] to i32
+; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[AND]], i1 false)
+; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[ABS]], 1
+; CHECK-NEXT: ret i32 [[ADD]]
+;
+ %ext = sext i30 %x to i32
+ %abs = call i32 @llvm.abs.i32(i32 %ext, i1 false)
+ %add = add i32 %abs, 1
+ ret i32 %add
+}
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -3001,6 +3001,19 @@
"Failed to determine minimum sign bits");
return Tmp;
}
+ case Instruction::Call: {
+ if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(U)) {
+ switch (II->getIntrinsicID()) {
+ default: break;
+ case Intrinsic::abs:
+ Tmp = ComputeNumSignBits(U->getOperand(0), Depth + 1, Q);
+ if (Tmp == 1) break;
+
+ // Absolute value reduces number of sign bits by at most 1.
+ return Tmp - 1;
+ }
+ }
+ }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84971.282014.patch
Type: text/x-patch
Size: 1583 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200730/13db9dbe/attachment.bin>
More information about the llvm-commits
mailing list