From 2d8b55c4769d905f588d9eb95e66674e7bdbb3db Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 9 May 2005 22:17:13 +0000 Subject: The semantics of cast X to bool are a comparison against zero, not a truncation! llvm-svn: 21833 --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'llvm') diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 8dbf78c270e..d6ec50ae166 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -493,6 +493,11 @@ void SelectionDAGLowering::visitCast(User &I) { if (N.getValueType() == DestTy) { setValue(&I, N); // noop cast. + } else if (DestTy == MVT::i1) { + // Cast to bool is a comparison against zero, not truncation to zero. + SDOperand Zero = isInteger(SrcTy) ? DAG.getConstant(0, N.getValueType()) : + DAG.getConstantFP(0.0, N.getValueType()); + setValue(&I, DAG.getSetCC(ISD::SETNE, MVT::i1, N, Zero)); } else if (isInteger(SrcTy)) { if (isInteger(DestTy)) { // Int -> Int cast if (DestTy < SrcTy) // Truncating cast? -- cgit v1.2.3