[llvm] r239682 - [DAGCombiner] Added BSWAP(BSWAP(x)) -> x combine pattern.
Simon Pilgrim
llvm-dev at redking.me.uk
Sat Jun 13 09:25:13 PDT 2015
Author: rksimon
Date: Sat Jun 13 11:25:12 2015
New Revision: 239682
URL: http://llvm.org/viewvc/llvm-project?rev=239682&view=rev
Log:
[DAGCombiner] Added BSWAP(BSWAP(x)) -> x combine pattern.
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/trunk/test/CodeGen/X86/bswap-vector.ll
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=239682&r1=239681&r2=239682&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Sat Jun 13 11:25:12 2015
@@ -4773,6 +4773,9 @@ SDValue DAGCombiner::visitBSWAP(SDNode *
// fold (bswap c1) -> c2
if (isConstantIntBuildVectorOrConstantInt(N0))
return DAG.getNode(ISD::BSWAP, SDLoc(N), VT, N0);
+ // fold (bswap (bswap x)) -> x
+ if (N0.getOpcode() == ISD::BSWAP)
+ return N0->getOperand(0);
return SDValue();
}
Modified: llvm/trunk/test/CodeGen/X86/bswap-vector.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/bswap-vector.ll?rev=239682&r1=239681&r2=239682&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/bswap-vector.ll (original)
+++ llvm/trunk/test/CodeGen/X86/bswap-vector.ll Sat Jun 13 11:25:12 2015
@@ -287,6 +287,80 @@ entry:
}
;
+; Double BSWAP -> Identity
+;
+
+define <8 x i16> @identity_v8i16(<8 x i16> %v) {
+; CHECK-ALL-LABEL: identity_v8i16:
+; CHECK-ALL: # BB#0: # %entry
+; CHECK-ALL: retq
+entry:
+ %bs1 = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %v)
+ %bs2 = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %bs1)
+ ret <8 x i16> %bs2
+}
+
+define <4 x i32> @identity_v4i32(<4 x i32> %v) {
+; CHECK-ALL-LABEL: identity_v4i32:
+; CHECK-ALL: # BB#0: # %entry
+; CHECK-ALL-NEXT: retq
+entry:
+ %bs1 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %v)
+ %bs2 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %bs1)
+ ret <4 x i32> %bs2
+}
+
+define <2 x i64> @identity_v2i64(<2 x i64> %v) {
+; CHECK-ALL-LABEL: identity_v2i64:
+; CHECK-ALL: # BB#0: # %entry
+; CHECK-ALL-NEXT: retq
+entry:
+ %bs1 = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %v)
+ %bs2 = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %bs1)
+ ret <2 x i64> %bs2
+}
+
+define <16 x i16> @identity_v16i16(<16 x i16> %v) {
+; CHECK-ALL-LABEL: identity_v16i16:
+; CHECK-ALL: # BB#0: # %entry
+; CHECK-ALL-NEXT: retq
+entry:
+ %bs1 = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %v)
+ %bs2 = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %bs1)
+ ret <16 x i16> %bs2
+}
+
+define <8 x i32> @identity_v8i32(<8 x i32> %v) {
+; CHECK-ALL-LABEL: identity_v8i32:
+; CHECK-ALL: # BB#0: # %entry
+; CHECK-ALL-NEXT: retq
+entry:
+ %bs1 = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %v)
+ %bs2 = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %bs1)
+ ret <8 x i32> %bs2
+}
+
+define <4 x i64> @identity_v4i64(<4 x i64> %v) {
+; CHECK-ALL-LABEL: identity_v4i64:
+; CHECK-ALL: # BB#0: # %entry
+; CHECK-ALL-NEXT: retq
+entry:
+ %bs1 = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %v)
+ %bs2 = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %bs1)
+ ret <4 x i64> %bs2
+}
+
+define <4 x i16> @identity_v4i16(<4 x i16> %v) {
+; CHECK-ALL-LABEL: identity_v4i16:
+; CHECK-ALL: # BB#0: # %entry
+; CHECK-ALL-NEXT: retq
+entry:
+ %bs1 = call <4 x i16> @llvm.bswap.v4i16(<4 x i16> %v)
+ %bs2 = call <4 x i16> @llvm.bswap.v4i16(<4 x i16> %bs1)
+ ret <4 x i16> %bs2
+}
+
+;
; Constant Folding
;
More information about the llvm-commits
mailing list