[llvm-commits] [llvm] r143095 - in /llvm/trunk: lib/CodeGen/SelectionDAG/DAGCombiner.cpp test/CodeGen/X86/i128-sdiv.ll
Eli Friedman
eli.friedman at gmail.com
Wed Oct 26 19:06:39 PDT 2011
Author: efriedma
Date: Wed Oct 26 21:06:39 2011
New Revision: 143095
URL: http://llvm.org/viewvc/llvm-project?rev=143095&view=rev
Log:
Don't crash on 128-bit sdiv by constant. Found by inspection.
Added:
llvm/trunk/test/CodeGen/X86/i128-sdiv.ll
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=143095&r1=143094&r2=143095&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Wed Oct 26 21:06:39 2011
@@ -1756,7 +1756,7 @@
if (N0C && N1C && !N1C->isNullValue())
return DAG.FoldConstantArithmetic(ISD::SDIV, VT, N0C, N1C);
// fold (sdiv X, 1) -> X
- if (N1C && N1C->getSExtValue() == 1LL)
+ if (N1C && N1C->getAPIntValue() == 1LL)
return N0;
// fold (sdiv X, -1) -> 0-X
if (N1C && N1C->isAllOnesValue())
@@ -1771,16 +1771,14 @@
}
// fold (sdiv X, pow2) -> simple ops after legalize
if (N1C && !N1C->isNullValue() && !TLI.isIntDivCheap() &&
- (isPowerOf2_64(N1C->getSExtValue()) ||
- isPowerOf2_64(-N1C->getSExtValue()))) {
+ (N1C->getAPIntValue().isPowerOf2() ||
+ (-N1C->getAPIntValue()).isPowerOf2())) {
// If dividing by powers of two is cheap, then don't perform the following
// fold.
if (TLI.isPow2DivCheap())
return SDValue();
- int64_t pow2 = N1C->getSExtValue();
- int64_t abs2 = pow2 > 0 ? pow2 : -pow2;
- unsigned lg2 = Log2_64(abs2);
+ unsigned lg2 = N1C->getAPIntValue().countTrailingZeros();
// Splat the sign bit into the register
SDValue SGN = DAG.getNode(ISD::SRA, N->getDebugLoc(), VT, N0,
@@ -1800,7 +1798,7 @@
// If we're dividing by a positive value, we're done. Otherwise, we must
// negate the result.
- if (pow2 > 0)
+ if (N1C->getAPIntValue().isNonNegative())
return SRA;
AddToWorkList(SRA.getNode());
@@ -1810,8 +1808,7 @@
// if integer divide is expensive and we satisfy the requirements, emit an
// alternate sequence.
- if (N1C && (N1C->getSExtValue() < -1 || N1C->getSExtValue() > 1) &&
- !TLI.isIntDivCheap()) {
+ if (N1C && !N1C->isNullValue() && !TLI.isIntDivCheap()) {
SDValue Op = BuildSDIV(N);
if (Op.getNode()) return Op;
}
Added: llvm/trunk/test/CodeGen/X86/i128-sdiv.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/i128-sdiv.ll?rev=143095&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/i128-sdiv.ll (added)
+++ llvm/trunk/test/CodeGen/X86/i128-sdiv.ll Wed Oct 26 21:06:39 2011
@@ -0,0 +1,24 @@
+; RUN: llc < %s -march=x86-64 | FileCheck %s
+; Make sure none of these crash, and that the power-of-two transformations
+; trigger correctly.
+
+define i128 @test1(i128 %x) {
+ ; CHECK: test1:
+ ; CHECK-NOT: call
+ %tmp = sdiv i128 %x, 73786976294838206464
+ ret i128 %tmp
+}
+
+define i128 @test2(i128 %x) {
+ ; CHECK: test2:
+ ; CHECK-NOT: call
+ %tmp = sdiv i128 %x, -73786976294838206464
+ ret i128 %tmp
+}
+
+define i128 @test3(i128 %x) {
+ ; CHECK: test3:
+ ; CHECK: call
+ %tmp = sdiv i128 %x, -73786976294838206467
+ ret i128 %tmp
+}
More information about the llvm-commits
mailing list