[llvm-commits] [llvm] r159739 - in /llvm/trunk: lib/CodeGen/SelectionDAG/TargetLowering.cpp test/CodeGen/X86/sext-setcc-self.ll
Duncan Sands
baldrick at free.fr
Thu Jul 5 02:32:46 PDT 2012
Author: baldrick
Date: Thu Jul 5 04:32:46 2012
New Revision: 159739
URL: http://llvm.org/viewvc/llvm-project?rev=159739&view=rev
Log:
Use the right kind of booleans: we were emitting 0/1 booleans, instead of 0/-1
booleans. Patch by James Benton.
Added:
llvm/trunk/test/CodeGen/X86/sext-setcc-self.ll
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp?rev=159739&r1=159738&r2=159739&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp Thu Jul 5 04:32:46 2012
@@ -2390,21 +2390,29 @@
}
if (N0 == N1) {
+ // The sext(setcc()) => setcc() optimization relies on the appropriate
+ // constant being emitted.
+ uint64_t EqVal;
+ switch (getBooleanContents(N0.getValueType().isVector())) {
+ default: llvm_unreachable("Unknown boolean contents!");
+ case UndefinedBooleanContent:
+ case ZeroOrOneBooleanContent:
+ EqVal = ISD::isTrueWhenEqual(Cond);
+ break;
+ case ZeroOrNegativeOneBooleanContent:
+ EqVal = ISD::isTrueWhenEqual(Cond) ? -1 : 0;
+ break;
+ }
+
// We can always fold X == X for integer setcc's.
if (N0.getValueType().isInteger()) {
- switch (getBooleanContents(N0.getValueType().isVector())) {
- case UndefinedBooleanContent:
- case ZeroOrOneBooleanContent:
- return DAG.getConstant(ISD::isTrueWhenEqual(Cond), VT);
- case ZeroOrNegativeOneBooleanContent:
- return DAG.getConstant(ISD::isTrueWhenEqual(Cond) ? -1 : 0, VT);
- }
+ return DAG.getConstant(EqVal, VT);
}
unsigned UOF = ISD::getUnorderedFlavor(Cond);
if (UOF == 2) // FP operators that are undefined on NaNs.
- return DAG.getConstant(ISD::isTrueWhenEqual(Cond), VT);
+ return DAG.getConstant(EqVal, VT);
if (UOF == unsigned(ISD::isTrueWhenEqual(Cond)))
- return DAG.getConstant(UOF, VT);
+ return DAG.getConstant(EqVal, VT);
// Otherwise, we can't fold it. However, we can simplify it to SETUO/SETO
// if it is not already.
ISD::CondCode NewCond = UOF == 0 ? ISD::SETO : ISD::SETUO;
Added: llvm/trunk/test/CodeGen/X86/sext-setcc-self.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/sext-setcc-self.ll?rev=159739&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/sext-setcc-self.ll (added)
+++ llvm/trunk/test/CodeGen/X86/sext-setcc-self.ll Thu Jul 5 04:32:46 2012
@@ -0,0 +1,55 @@
+; RUN: llc -march=x86 -mcpu=nehalem < %s | FileCheck %s
+
+define <4 x i32> @test_ueq(<4 x float> %in) {
+entry:
+ ; CHECK: pcmpeqd %xmm0, %xmm0
+ ; CHECK-NEXT: ret
+ %0 = fcmp ueq <4 x float> %in, %in
+ %1 = sext <4 x i1> %0 to <4 x i32>
+ ret <4 x i32> %1
+}
+
+define <4 x i32> @test_uge(<4 x float> %in) {
+entry:
+ ; CHECK: pcmpeqd %xmm0, %xmm0
+ ; CHECK-NEXT: ret
+ %0 = fcmp uge <4 x float> %in, %in
+ %1 = sext <4 x i1> %0 to <4 x i32>
+ ret <4 x i32> %1
+}
+
+define <4 x i32> @test_ule(<4 x float> %in) {
+entry:
+ ; CHECK: pcmpeqd %xmm0, %xmm0
+ ; CHECK-NEXT: ret
+ %0 = fcmp ule <4 x float> %in, %in
+ %1 = sext <4 x i1> %0 to <4 x i32>
+ ret <4 x i32> %1
+}
+
+define <4 x i32> @test_one(<4 x float> %in) {
+entry:
+ ; CHECK: xorps %xmm0, %xmm0
+ ; CHECK-NEXT: ret
+ %0 = fcmp one <4 x float> %in, %in
+ %1 = sext <4 x i1> %0 to <4 x i32>
+ ret <4 x i32> %1
+}
+
+define <4 x i32> @test_ogt(<4 x float> %in) {
+entry:
+ ; CHECK: xorps %xmm0, %xmm0
+ ; CHECK-NEXT: ret
+ %0 = fcmp ogt <4 x float> %in, %in
+ %1 = sext <4 x i1> %0 to <4 x i32>
+ ret <4 x i32> %1
+}
+
+define <4 x i32> @test_olt(<4 x float> %in) {
+entry:
+ ; CHECK: xorps %xmm0, %xmm0
+ ; CHECK-NEXT: ret
+ %0 = fcmp olt <4 x float> %in, %in
+ %1 = sext <4 x i1> %0 to <4 x i32>
+ ret <4 x i32> %1
+}
More information about the llvm-commits
mailing list