[llvm] r276855 - [DAGCombiner] Use APInt directly to detect out of range shift constants
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 27 03:30:55 PDT 2016
Author: rksimon
Date: Wed Jul 27 05:30:55 2016
New Revision: 276855
URL: http://llvm.org/viewvc/llvm-project?rev=276855&view=rev
Log:
[DAGCombiner] Use APInt directly to detect out of range shift constants
Using getZExtValue() will assert if the value doesn't fit into uint64_t - SHL was already doing this, I've just updated ASHR/LSHR to match
As mentioned on D22726
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/trunk/test/CodeGen/X86/shift-i128.ll
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=276855&r1=276854&r2=276855&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Wed Jul 27 05:30:55 2016
@@ -4634,8 +4634,8 @@ SDValue DAGCombiner::visitSRA(SDNode *N)
// fold (sra -1, x) -> -1
if (isAllOnesConstant(N0))
return N0;
- // fold (sra x, (setge c, size(x))) -> undef
- if (N1C && N1C->getZExtValue() >= OpSizeInBits)
+ // fold (sra x, c >= size(x)) -> undef
+ if (N1C && N1C->getAPIntValue().uge(OpSizeInBits))
return DAG.getUNDEF(VT);
// fold (sra x, 0) -> x
if (N1C && N1C->isNullValue())
@@ -4778,7 +4778,7 @@ SDValue DAGCombiner::visitSRL(SDNode *N)
if (isNullConstant(N0))
return N0;
// fold (srl x, c >= size(x)) -> undef
- if (N1C && N1C->getZExtValue() >= OpSizeInBits)
+ if (N1C && N1C->getAPIntValue().uge(OpSizeInBits))
return DAG.getUNDEF(VT);
// fold (srl x, 0) -> x
if (N1C && N1C->isNullValue())
Modified: llvm/trunk/test/CodeGen/X86/shift-i128.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/shift-i128.ll?rev=276855&r1=276854&r2=276855&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/shift-i128.ll (original)
+++ llvm/trunk/test/CodeGen/X86/shift-i128.ll Wed Jul 27 05:30:55 2016
@@ -1,9 +1,94 @@
-; RUN: llc < %s -march=x86
-; RUN: llc < %s -march=x86-64
-
-define void @t(i128 %x, i128 %a, i128* nocapture %r) nounwind {
-entry:
- %0 = lshr i128 %x, %a
- store i128 %0, i128* %r, align 16
- ret void
-}
+; RUN: llc < %s -march=x86
+; RUN: llc < %s -march=x86-64
+
+;
+; Scalars
+;
+
+define void @test_lshr_i128(i128 %x, i128 %a, i128* nocapture %r) nounwind {
+entry:
+ %0 = lshr i128 %x, %a
+ store i128 %0, i128* %r, align 16
+ ret void
+}
+
+define void @test_ashr_i128(i128 %x, i128 %a, i128* nocapture %r) nounwind {
+entry:
+ %0 = ashr i128 %x, %a
+ store i128 %0, i128* %r, align 16
+ ret void
+}
+
+define void @test_shl_i128(i128 %x, i128 %a, i128* nocapture %r) nounwind {
+entry:
+ %0 = shl i128 %x, %a
+ store i128 %0, i128* %r, align 16
+ ret void
+}
+
+define void @test_lshr_i128_outofrange(i128 %x, i128* nocapture %r) nounwind {
+entry:
+ %0 = lshr i128 %x, -1
+ store i128 %0, i128* %r, align 16
+ ret void
+}
+
+define void @test_ashr_i128_outofrange(i128 %x, i128* nocapture %r) nounwind {
+entry:
+ %0 = ashr i128 %x, -1
+ store i128 %0, i128* %r, align 16
+ ret void
+}
+
+define void @test_shl_i128_outofrange(i128 %x, i128* nocapture %r) nounwind {
+entry:
+ %0 = shl i128 %x, -1
+ store i128 %0, i128* %r, align 16
+ ret void
+}
+
+;
+; Vectors
+;
+
+define void @test_lshr_v2i128(<2 x i128> %x, <2 x i128> %a, <2 x i128>* nocapture %r) nounwind {
+entry:
+ %0 = lshr <2 x i128> %x, %a
+ store <2 x i128> %0, <2 x i128>* %r, align 16
+ ret void
+}
+
+define void @test_ashr_v2i128(<2 x i128> %x, <2 x i128> %a, <2 x i128>* nocapture %r) nounwind {
+entry:
+ %0 = ashr <2 x i128> %x, %a
+ store <2 x i128> %0, <2 x i128>* %r, align 16
+ ret void
+}
+
+define void @test_shl_v2i128(<2 x i128> %x, <2 x i128> %a, <2 x i128>* nocapture %r) nounwind {
+entry:
+ %0 = shl <2 x i128> %x, %a
+ store <2 x i128> %0, <2 x i128>* %r, align 16
+ ret void
+}
+
+define void @test_lshr_v2i128_outofrange(<2 x i128> %x, <2 x i128>* nocapture %r) nounwind {
+entry:
+ %0 = lshr <2 x i128> %x, <i128 -1, i128 -1>
+ store <2 x i128> %0, <2 x i128>* %r, align 16
+ ret void
+}
+
+define void @test_ashr_v2i128_outofrange(<2 x i128> %x, <2 x i128>* nocapture %r) nounwind {
+entry:
+ %0 = ashr <2 x i128> %x, <i128 -1, i128 -1>
+ store <2 x i128> %0, <2 x i128>* %r, align 16
+ ret void
+}
+
+define void @test_shl_v2i128_outofrange(<2 x i128> %x, <2 x i128>* nocapture %r) nounwind {
+entry:
+ %0 = shl <2 x i128> %x, <i128 -1, i128 -1>
+ store <2 x i128> %0, <2 x i128>* %r, align 16
+ ret void
+}
More information about the llvm-commits
mailing list