Commits

Chris Lattner committed 7733b060c57
Enhance IRGen to know a simple heuristic in emitValueBitCast to avoid going to the stack when two explosions will end up with the same elements. This helps with optional to optional conversions. We now compile: public func opt_to_opt_trivial(x: Int?) -> Int! { return x } public func opt_to_opt_reference(x : C!) -> C? { return x } into: define { i64, i1 } @_TF1x18opt_to_opt_trivialFGSqSi_GSQSi_(i64, i1) { entry: %2 = insertvalue { i64, i1 } undef, i64 %0, 0 %3 = insertvalue { i64, i1 } %2, i1 %1, 1 ret { i64, i1 } %3 } define i64 @_TF1x20opt_to_opt_referenceFGSQCS_1C_GSqS0__(i64) { entry: ret i64 %0 } instead of: define { i64, i1 } @_TF1x18opt_to_opt_trivialFGSqSi_GSQSi_(i64, i1) { entry: %bitcast = alloca %Sq, align 8 %2 = bitcast %Sq* %bitcast to i64* store i64 %0, i64* %2, align 8 %3 = getelementptr inbounds %Sq, %Sq* %bitcast, i32 0, i32 1 %4 = bitcast [1 x i8]* %3 to i1* store i1 %1, i1* %4, align 8 %5 = bitcast %Sq* %bitcast to %SQ* %6 = bitcast %SQ* %5 to i64* %7 = load i64, i64* %6, align 8 %8 = getelementptr inbounds %SQ, %SQ* %5, i32 0, i32 1 %9 = bitcast [1 x i8]* %8 to i1* %10 = load i1, i1* %9, align 8 %11 = insertvalue { i64, i1 } undef, i64 %7, 0 %12 = insertvalue { i64, i1 } %11, i1 %10, 1 ret { i64, i1 } %12 } define i64 @_TF1x20opt_to_opt_referenceFGSQCS_1C_GSqS0__(i64) { entry: %bitcast = alloca %SQ.17, align 8 %1 = bitcast %SQ.17* %bitcast to i64* store i64 %0, i64* %1, align 8 %2 = bitcast %SQ.17* %bitcast to %Sq.16* %3 = bitcast %Sq.16* %2 to i64* %4 = load i64, i64* %3, align 8 ret i64 %4 } Swift SVN r28107